licheng700

          BlogJava 首頁 新隨筆 聯(lián)系 聚合 管理
            26 Posts :: 5 Stories :: 5 Comments :: 1 Trackbacks

          select  n_accountid,accountNO,accountName ,
          sum(decode(n_direction,1,n_amount, 0)) amountOfDebit,
          sum(decode(n_direction,2,n_amount, 0)) amountOfCredit,
          sum(n_amount) amount,
          sum(decode(n_direction,1,1, 0)) numOfDebitTrans,
          sum(decode(n_direction,2,1, 0)) numOfCreditTrans,
          COUNT(n_direction) nums
          from

          (select a.n_accountid n_accountid ,
          a.n_amount n_amount,a.n_direction n_direction,
          b.s_accountno accountNO,b.s_accountname  accountName from

          (select n_id ,n_accountid,n_currencytype,n_amount,n_direction,dt_modifytime from bs_accthistransinfo where 1=1
           and to_char(dt_modifytime,'yyyy-mm-dd')>='2005-01-01'
           and to_char(dt_modifytime,'yyyy-mm-dd')<='2006-01-01'
           union all
          select n_id ,n_accountid,n_currencytype,n_amount,n_direction,dt_modifytime from bs_acctcurtransinfo where 1=1
           and to_char(dt_modifytime,'yyyy-mm-dd')>='2005-01-01'
           and to_char(dt_modifytime,'yyyy-mm-dd')<='2006-01-01'
          )a,  

          (select n_id,s_accountno,s_accountname,n_currencytype from bs_bankaccountinfo where
              n_ischeck=1
           and n_accountstatus= 1)
           b
           where a.n_currencytype=b.n_currencytype  and a.n_accountid=b.n_id
          )
          c
          group by n_accountid,accountNO,accountName


           

          posted on 2005-08-25 16:31 小海船 閱讀(181) 評論(1)  編輯  收藏

          評論

          # re: 一段SQL 2005-08-25 17:02 小海船
          select n_accountid,accountNO,accountName ,
          sum(decode(n_direction,1,n_amount, 0)) amountOfDebit,
          sum(decode(n_direction,2,n_amount, 0)) amountOfCredit,
          sum(n_amount) amount,
          sum(decode(n_direction,1,1, 0)) numOfDebitTrans,
          sum(decode(n_direction,2,1, 0)) numOfCreditTrans,
          COUNT(n_direction) nums
          from
          (select a.n_id n_id,a.n_accountid n_accountid ,a.n_currencytype n_currencytype,
          a.n_amount n_amount,a.n_direction n_direction,a.dt_modifytime dt_modifytime,
          b.s_accountno accountNO,b.s_accountname accountName from
          (select n_id ,n_accountid,n_currencytype,n_amount,n_direction,dt_modifytime from bs_accthistransinfo where 1=1
          union all
          select n_id ,n_accountid,n_currencytype,n_amount,n_direction,dt_modifytime from bs_acctcurtransinfo where 1=1)
          a,
          (select * from bs_bankaccountinfo where
          n_accountstatus= 1
          and n_ischeck=1) b where a.n_currencytype=b.n_currencytype and a.n_accountid=b.n_id and
          to_char(a.dt_modifytime,'yyyy-mm-dd')>='2005-01-01' and
          to_char(a.dt_modifytime,'yyyy-mm-dd')<='2006-01-01'
          )c group by n_accountid,accountNO,accountName  回復  更多評論
            


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 屏山县| 德安县| 湾仔区| 黔东| 综艺| 临沭县| 左贡县| 襄汾县| 广饶县| 九龙城区| 长岭县| 日照市| 黑水县| 通海县| 邯郸县| 灵石县| 瓦房店市| 建德市| 平谷区| 天水市| 盐山县| 南岸区| 商城县| 赞皇县| 汝城县| 兴城市| 留坝县| 永春县| 宝鸡市| 任丘市| 云阳县| 洛浦县| 辉县市| 靖西县| 涞水县| 南京市| 咸宁市| 贵阳市| 和静县| 当雄县| 巩留县|