資金歸集率比率sql

 基礎資料sql

select bd_glorgbook.glorgbookcode,
nvl(replace(bd_glorgbook.glorgbookname,'集團基準帳薄',''),'小計')公司名稱, --從蘿蔔那裏學習

substr(bd_accsubj.subjcode,1,4)科目編碼,---1111應收票據(借方),1131應收帳款(+貸-借),2123工程結算
--如下是貸方
sum( case when gl_balance.year= '2012' then gl_balance.debitamount else 0 end) "2012借方發生額",
sum( case when gl_balance.year= '2013' then gl_balance.debitamount else 0 end) "2013借方發生額",
sum( case when gl_balance.year= '2014' then gl_balance.debitamount else 0 end) "2014借方發生額" , 
sum( case when gl_balance.year= '2015' then gl_balance.debitamount else 0 end) "2015借方發生額" ,
--如下是貸方
sum( case when gl_balance.year= '2012' then gl_balance.creditamount else 0 end) "2012貸方發生額",
sum( case when gl_balance.year= '2013' then gl_balance.creditamount else 0 end) "2013貸方發生額",
sum( case when gl_balance.year= '2014' then gl_balance.creditamount else 0 end) "2014貸方發生額" , 
sum( case when gl_balance.year= '2015' then gl_balance.creditamount else 0 end) "2015貸方發生額" 
from gl_balance, bd_accsubj, bd_glorgbook
where gl_balance.pk_accsubj = bd_accsubj.pk_accsubj
and bd_glorgbook.pk_glorgbook = gl_balance.pk_glorgbook
and bd_glorgbook.glorgbookcode like '01%-0001' 
and (bd_accsubj.subjcode like '2123%' or bd_accsubj.subjcode like '1131%'or bd_accsubj.subjcode like '1111%')
and gl_balance.period<>'00'
and gl_balance.year in('2012','2013','2014','2015')
group by bd_glorgbook.glorgbookcode, rollup((substr(bd_accsubj.subjcode,1,4), bd_glorgbook.glorgbookname)) 

order by bd_glorgbook.glorgbookcode, substr(bd_accsubj.subjcode,1,4)

經過substr取一級學習

2015-10-13 08:50:00 計算工程款編碼

select bd_glorgbook.glorgbookcode,
nvl(replace(bd_glorgbook.glorgbookname,'集團基準帳薄',''),'小計')公司名稱, --從蘿蔔那裏學習

--substr(bd_accsubj.subjcode,1,4)科目編碼,---1111應收票據(借方),1131應收帳款(+貸-借),2123工程結算

--如下是貸方
sum( case when gl_balance.year= '2012' then gl_balance.creditamount else 0 end) "2012貸方發生額",
sum( case when gl_balance.year= '2013' then gl_balance.creditamount else 0 end) "2013貸方發生額",
sum( case when gl_balance.year= '2014' then gl_balance.creditamount else 0 end) "2014貸方發生額" , 
sum( case when gl_balance.year= '2015' and gl_balance.period<=6 then gl_balance.creditamount else 0 end) "2015貸方發生額" 
from gl_balance, bd_accsubj, bd_glorgbook
where gl_balance.pk_accsubj = bd_accsubj.pk_accsubj
and bd_glorgbook.pk_glorgbook = gl_balance.pk_glorgbook
and bd_glorgbook.glorgbookcode like '01%-0001' 
and (bd_accsubj.subjcode like '2123%' )
and gl_balance.period<>'00'
and gl_balance.year in('2012','2013','2014','2015')
group by bd_glorgbook.glorgbookcode, substr(bd_accsubj.subjcode,1,4), bd_glorgbook.glorgbookname
order by bd_glorgbook.glorgbookcode, substr(bd_accsubj.subjcode,1,4)

2015年6月的工程款中gl_balance須要是<=不能是=,6也不須要引號(=6爲當月的餘額),必須記帳才能取到spa

歸集sqlrest

select bd_accid.accidcode,
       bd_accid.accidname,
      sum( case when substr(fts_voucher_b.interestdate, 1, 4)= '2012' then fts_voucher_b.creditamount else 0 end) "2012歸集額",
sum( case when substr(fts_voucher_b.interestdate, 1, 4)= '2013' then fts_voucher_b.creditamount else 0 end) "2013歸集額",
sum( case when substr(fts_voucher_b.interestdate, 1, 4)= '2014' then fts_voucher_b.creditamount else 0 end) "2014歸集額" , 
sum( case when substr(fts_voucher_b.interestdate, 1, 4)= '2015' then fts_voucher_b.creditamount else 0 end) "2015歸集額"  
  from fts_voucher_b, bd_accid
 where fts_voucher_b.dr = '0'
   and fts_voucher_b.pk_corp = '1162'
   and fts_voucher_b.pk_account = bd_accid.pk_accid
  -- and bd_accid.accidcode = '011501' --公司
   and fts_voucher_b.creditamount <> 0
   and substr(fts_voucher_b.interestdate, 1, 4) in('2012','2013','2014','2015') --年份
   and fts_voucher_b.pk_ass not in
       (select freevalueid from gl_freevalue where valuecode = '777777') 
       group by bd_accid.accidcode, bd_accid.accidname 
 order by bd_accid.accidcode 

 委託中心付款合計sqlcode

select c.accidcode,c.accidname,

sum( case when a.cyear= '2012' then a.totalcredit else 0 end) "2012借方發生額",
sum( case when a.cyear= '2013' then a.totalcredit else 0 end) "2013借方發生額",
sum( case when a.cyear= '2014' then a.totalcredit else 0 end) "2014借方發生額" , 
sum( case when a.cyear= '2015' then a.totalcredit else 0 end) "2015借方發生額"  

from fts_voucher a,fts_voucher_b b, bd_accid c
 where a.pk_voucher=b.pk_voucher
 and b.pk_account=c.pk_accid
  and   a.cyear in('2012','2013','2014','2015')
  and a.datasource=2 --(6上收,2委託,5下撥,3到帳通知,0手工填制)
group by c.accidcode,c.accidname 
order by c.accidcode
 

 待研究blog

select c.accidcode,c.accidname,ci

sum( case when a.cyear= '2012' then a.totalcredit else 0 end) "2012借方發生額",
sum( case when a.cyear= '2013' then a.totalcredit else 0 end) "2013借方發生額",
sum( case when a.cyear= '2014' then a.totalcredit else 0 end) "2014借方發生額" ,
sum( case when a.cyear= '2015' then a.totalcredit else 0 end) "2015借方發生額" it

from fts_voucher a,fts_voucher_b b, bd_accid c
where a.pk_voucher=b.pk_voucher
and b.pk_account=c.pk_accid
and a.cyear in('2012','2013','2014','2015')
and a.datasource=2 --(6上收,2委託,5下撥,3到帳通知,0手工填制)
and fts_voucher_b.pk_ass not in
(select freevalueid from gl_freevalue where valuecode = '777777')
group by c.accidcode,c.accidname
order by c.accidcodeio

2015-10-12 09:31:13 整合 去掉內部轉帳的委託付款

select c.accidcode,c.accidname,

sum( case when a.cyear= '2012' then a.totalcredit else 0 end) "2012借方發生額",
sum( case when a.cyear= '2013' then a.totalcredit else 0 end) "2013借方發生額",
sum( case when a.cyear= '2014' then a.totalcredit else 0 end) "2014借方發生額" , 
sum( case when a.cyear= '2015' then a.totalcredit else 0 end) "2015借方發生額"  

from fts_voucher a,fts_voucher_b b, bd_accid c
 where a.pk_voucher=b.pk_voucher
 and b.pk_account=c.pk_accid
  and   a.cyear in('2012','2013','2014','2015')
  and a.datasource=2 --(6上收,2委託,5下撥,3到帳通知,0手工填制)
and b.pk_ass not in
(select freevalueid from gl_freevalue where valuecode = '777777') 
group by c.accidcode,c.accidname 
order by c.accidcode
相關文章
相關標籤/搜索