管理費用linux
爲了獲得科目名稱,只好再從外面寫一層sql
select a.*, (select b.subjname from bd_accsubj b where b.subjcode=a.scode and b.pk_glorgbook='0001E1100000000000MX') 項目--從總部機關的會計科目獲得名稱 from ( select substr(bd_accsubj.subjcode,1,6)scode, sum( case when gl_balance.year= '2014' then gl_balance.debitamount else 0 end) "2014發生額", sum( case when gl_balance.year= '2013' then gl_balance.debitamount else 0 end) "2013發生額", sum( case when gl_balance.year= '2012' then gl_balance.debitamount else 0 end) "2012發生額" 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 '5502%' ) and gl_balance.period<>'00' and gl_balance.year in('2012','2013','2014') group by substr(bd_accsubj.subjcode,1,6) order by substr(bd_accsubj.subjcode,1,6))a order by a.scode
去除2012總一,2013總五 case 增長條件,完美函數
select a.*,b.subjname from ( select substr(bd_accsubj.subjcode,1,6)scode, sum( case when gl_balance.year= '2012' and bd_glorgbook.glorgbookcode<>'015101-0001' then gl_balance.debitamount else 0 end) "2012發生額", sum( case when gl_balance.year= '2013' and bd_glorgbook.glorgbookcode<>'015501-0001' then gl_balance.debitamount else 0 end) "2013發生額", sum( case when gl_balance.year= '2014' then gl_balance.debitamount else 0 end) "2014發生額" 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 '5502%' ) and gl_balance.period<>'00' and gl_balance.year in('2012','2013','2014') group by substr(bd_accsubj.subjcode,1,6) order by substr(bd_accsubj.subjcode,1,6))a,bd_accsubj b where a.scode=b.subjcode and b.pk_glorgbook='0001E1100000000000MX' order by a.scode
銀行存款的發生額編碼
select bd_accsubj.subjcode,bd_accsubj.subjname, sum( case when gl_balance.year= '2014' then gl_balance.debitamount else 0 end) "2014借方發生額", sum( case when gl_balance.year= '2014' then gl_balance.creditamount else 0 end) "2014貸方發生額", sum( case when gl_balance.year= '2013' then gl_balance.debitamount else 0 end) "2013借方發生額", sum( case when gl_balance.year= '2013' then gl_balance.creditamount else 0 end) "2013貸方發生額", sum( case when gl_balance.year= '2012' then gl_balance.debitamount else 0 end) "2012借方發生額" , sum( case when gl_balance.year= '2012' then gl_balance.creditamount else 0 end) "2012貸方發生額" 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 = '030101-0001' and (bd_accsubj.subjcode like '1002%' ) and gl_balance.period<>'00' and gl_balance.year in('2012','2013','2014') group by bd_accsubj.subjcode,bd_accsubj.subjname order by bd_accsubj.subjcode
去除年底調帳的項目成本和結算(NC科目餘額和投標報表數字不一致)spa
select glorgbookcode, nvl(replace(glorgbookname,'集團基準帳薄',''),'小計')公司名稱, valuecode,valuename,sum(借方)成本,sum(貸方)收入 from ( select gl_freevalue.valuecode, gl_freevalue.valuename, gl_detail.prepareddatev 制單日期 , gl_voucher.no 憑證號, gl_detail.explanation, bd_accsubj.dispname, gl_detail.debitamount 借方, gl_detail.creditamount 貸方, gl_detail.pk_systemv, gl_voucher.pk_voucher, bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and gl_detail.yearv='2013' and bd_glorgbook.glorgbookcode = '010201-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%' or bd_accsubj.subjcode like '4104%')--只要工程施工和工程結算 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 and gl_detail.pk_voucher not in('1038N51000000000RIGV','1038N51000000000RIKG','1038N51000000000RIM3') -- 去除北京分包項目結算('1038N51000000000RIGV')、稅金('1038N51000000000RIKG')、成本('1038N51000000000RIM3') order by gl_detail.yearv,gl_detail.periodv,bd_accsubj.dispname,gl_voucher.no ) group by glorgbookcode,rollup((glorgbookname, valuecode,valuename)) order by glorgbookcode,valuecode
2015-11-13 09:38:00.net
審計要的項目成本二級明細3d
select glorgbookcode, glorgbookname,valuecode,valuename, substr(subjcode,1,8) 科目編碼,subjname 科目名稱,sum(借方)成本 from ( select gl_freevalue.valuecode, gl_freevalue.valuename, gl_detail.prepareddatev 制單日期 , gl_voucher.no 憑證號, gl_detail.explanation, bd_accsubj.subjcode, bd_accsubj.subjname, gl_detail.debitamount 借方, gl_detail.creditamount 貸方, gl_detail.pk_systemv, gl_voucher.pk_voucher, bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and gl_detail.yearv='2013' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '410401%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 order by gl_detail.yearv,gl_detail.periodv,gl_voucher.no ) group by glorgbookcode,glorgbookname, valuecode,valuename,substr(subjcode,1,8),subjname order by glorgbookcode,valuecode,substr(subjcode,1,8)
三年合一code
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename, substr(subjcode, 1,8), bd_accsubj.subjname, sum( case when gl_detail.yearv='2012' then gl_detail.debitamount else 0 end) "2012發生額", sum( case when gl_detail.yearv='2013' then gl_detail.debitamount else 0 end) "2013發生額", sum( case when gl_detail.yearv='2014' then gl_detail.debitamount else 0 end) "2014發生額" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '410401%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, valuecode,valuename, substr(bd_accsubj.subjcode, 1,8) ,subjname order by glorgbookcode,valuecode,substr(subjcode,1,8)
2016-11-02 10:22:30blog
施書雲要管理費用各公司排序
select bd_glorgbook.glorgbookname, gl_detail.prepareddatev 制單日期, gl_detail.explanation, bd_accsubj.dispname, gl_detail.debitamount 借方, gl_detail.creditamount 貸方, gl_voucher.no 憑證號 from bd_accsubj join gl_detail on gl_detail.pk_accsubj = bd_accsubj.pk_accsubj join bd_glorgbook on bd_glorgbook.pk_glorgbook = bd_accsubj.pk_glorgbook join gl_voucher on gl_detail.pk_voucher = gl_voucher.pk_voucher where gl_detail.dr = '0' and gl_detail.yearv = '2015' and bd_glorgbook.glorgbookcode like '01%01-0001' and gl_detail.periodv<>'00' and gl_detail.debitamount<>0 /* and gl_detail.explanation='付財大鳳凰樓項目人工費(洪榮森)'*/ and ( bd_accsubj.subjcode like '550216%' or bd_accsubj.subjcode like'550207%' ) order by bd_glorgbook.glorgbookcode,gl_detail.prepareddatev, bd_accsubj.subjcode
稅務局審計要的營業外支出
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_detail.prepareddatev 制單日期 , gl_voucher.no 憑證號, gl_detail.explanation 摘要, bd_accsubj.dispname 科目, gl_detail.debitamount 發生額 from gl_detail, bd_accsubj, bd_glorgbook, gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and gl_detail.yearv in ('2011','2012','2013','2014') and bd_glorgbook.glorgbookcode like '01%01-0001' and bd_accsubj.subjcode like '5601%' and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 order by gl_detail.yearv,bd_glorgbook.glorgbookcode,gl_detail.periodv,gl_voucher.no
改進的工程收款sql:至本年底收款等(強大大大大大大)
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename, sum( case when gl_detail.yearv<=2014 then gl_detail.creditamount else 0 end) "至本年底收款", sum( case when gl_detail.yearv<2014 then gl_detail.creditamount else 0 end) "至上年底收款", sum( case when gl_detail.yearv=2014 then gl_detail.creditamount else 0 end) "本年收款" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, valuecode,valuename order by glorgbookcode,valuecode
2016-08-24 11:37:55
責任人級別
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, substr(gl_freevalue.valuecode,1,6)"jobcode" , (select jobname from bd_jobbasfil where jobcode=substr(gl_freevalue.valuecode,1,6)) "jobname" , sum( case when gl_detail.yearv=2013 then gl_detail.creditamount else 0 end)/10000 "2013", sum( case when gl_detail.yearv=2014 then gl_detail.creditamount else 0 end)/10000 "2014", sum( case when gl_detail.yearv=2015 then gl_detail.creditamount else 0 end)/10000 "2015" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, substr(gl_freevalue.valuecode,1,6) order by glorgbookcode, substr(gl_freevalue.valuecode,1,6)
2016-09-13 09:57:52
單獨一個公司NC開始以後的收入
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode , gl_freevalue.valuename, (select begindate from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "開工時間" , (select forecastenddate from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "預計完工時間" , sum(gl_detail.creditamount )/10000 "收入" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '0104%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename order by glorgbookcode
2016-09-27 16:06:47 山東 秦經理要的
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode "jobcode" , gl_freevalue.valuename "jobname" , (select jobname from bd_jobbasfil where jobcode=substr(gl_freevalue.valuecode,1,6)) "責任人" , (select def2 from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "合同額" , sum( case when gl_detail.yearv=2010 then gl_detail.creditamount else 0 end)/10000 "2010", sum( case when gl_detail.yearv=2011 then gl_detail.creditamount else 0 end)/10000 "2011", sum( case when gl_detail.yearv=2012 then gl_detail.creditamount else 0 end)/10000 "2012" , sum( case when gl_detail.yearv=2013 then gl_detail.creditamount else 0 end)/10000 "2013", sum( case when gl_detail.yearv=2014 then gl_detail.creditamount else 0 end)/10000 "2014", sum( case when gl_detail.yearv=2015 then gl_detail.creditamount else 0 end)/10000 "2015", sum( case when gl_detail.yearv=2016 then gl_detail.creditamount else 0 end)/10000 "2016" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '0104%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename order by bd_glorgbook.glorgbookcode, gl_freevalue.valuecode
加上2016.6月的
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode "jobcode" , gl_freevalue.valuename "jobname" , (select jobname from bd_jobbasfil where jobcode=substr(gl_freevalue.valuecode,1,6)) "責任人" , (select def2 from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "合同額" , (select begindate from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "開工時間" , (select forecastenddate from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "預計完工時間" , sum( case when gl_detail.yearv=2010 and bd_glorgbook.glorgbookcode= '010402-0001' then gl_detail.creditamount else 0 end)/10000 "2010", sum( case when gl_detail.yearv=2011 and bd_glorgbook.glorgbookcode= '010401-0001'then gl_detail.creditamount else 0 end)/10000 "2011", sum( case when gl_detail.yearv=2012 then gl_detail.creditamount else 0 end)/10000 "2012" , sum( case when gl_detail.yearv=2013 then gl_detail.creditamount else 0 end)/10000 "2013", sum( case when gl_detail.yearv=2014 then gl_detail.creditamount else 0 end)/10000 "2014", sum( case when gl_detail.yearv=2015 then gl_detail.creditamount else 0 end)/10000 "2015", sum( case when gl_detail.yearv=2016 and gl_detail.periodv<=6 then gl_detail.creditamount else 0 end)/10000 "2016" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '0104%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename order by bd_glorgbook.glorgbookcode, gl_freevalue.valuecode
收入成本合成
select * from ( select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename, sum( case when gl_detail.yearv=2012 then gl_detail.creditamount else 0 end) INCOME, sum( case when gl_detail.yearv=2012 then gl_detail.debitamount else 0 end) COST from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '03%-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%' or bd_accsubj.subjcode like '4104%' )--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, valuecode,valuename) where INCOME<>0 OR COST<>0 order by glorgbookcode,valuecode
加上發包方
select a.*,b.def1 from (select * from ( select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename, sum( case when gl_detail.yearv=2015 then gl_detail.creditamount else 0 end) INCOME, sum( case when gl_detail.yearv=2015 then gl_detail.debitamount else 0 end) COST from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '03%01-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%' or bd_accsubj.subjcode like '4104%' )--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, valuecode,valuename) where INCOME<>0 OR COST<>0) a,bd_jobbasfil b where a.valuecode=b.jobcode order by glorgbookcode,valuecode
發包方改良
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname, gl_freevalue.valuecode "jobcode" , gl_freevalue.valuename "jobname" , (select jobname from bd_jobbasfil where jobcode=substr(gl_freevalue.valuecode,1,6)) "責任人" , (select def1 from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "發包方" , (select def2 from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "合同額" , sum( gl_detail.creditamount) "收款" from gl_detail, bd_accsubj, bd_glorgbook,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' and bd_glorgbook.glorgbookcode = '011601-0001' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by glorgbookcode,glorgbookname, gl_freevalue.valuecode, gl_freevalue.valuename order by bd_glorgbook.glorgbookcode, gl_freevalue.valuecode
2017-06-20 09:57:23 最終版
select gl_freevalue.valuecode "項目編碼", nvl(gl_freevalue.valuename,'小計') "項目名稱", (select jobname from bd_jobbasfil where jobcode=substr(gl_freevalue.valuecode,1,6)) "責任人" , (select def1 from bd_jobbasfil where jobcode=gl_freevalue.valuecode)"發包方" , (select def2 from bd_jobbasfil where jobcode=gl_freevalue.valuecode) "合同額" , sum( case when gl_detail.yearv=2008 then gl_detail.creditamount else 0 end)/10000 "2008", sum( case when gl_detail.yearv=2009 then gl_detail.creditamount else 0 end)/10000 "2009", sum( case when gl_detail.yearv=2010 then gl_detail.creditamount else 0 end)/10000 "2010", sum( case when gl_detail.yearv=2011 then gl_detail.creditamount else 0 end)/10000 "2011", sum( case when gl_detail.yearv=2012 then gl_detail.creditamount else 0 end)/10000 "2012", sum( case when gl_detail.yearv=2013 then gl_detail.creditamount else 0 end)/10000 "2013", sum( case when gl_detail.yearv=2014 then gl_detail.creditamount else 0 end)/10000 "2014", sum( case when gl_detail.yearv=2015 then gl_detail.creditamount else 0 end)/10000 "2015", sum( case when gl_detail.yearv=2016 then gl_detail.creditamount else 0 end)/10000 "2016", sum( case when gl_detail.yearv<2017 then gl_detail.creditamount else 0 end)/10000 "至上年底收款", sum( case when gl_detail.yearv=2017 and gl_detail.periodv<=5 then gl_detail.creditamount else 0 end)/10000 "本年收款", sum( case when gl_detail.prepareddatev<='2017-05-31' then gl_detail.creditamount else 0 end)/10000 "合計" from gl_detail, bd_accsubj, bd_corp,gl_freevalue,gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_corp = bd_corp.pk_corp and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_detail.dr = '0' -- and gl_detail.prepareddatev between #date1# and #date2# and bd_corp.unitcode like '0104%' -- and gl_freevalue.valuecode like #job1#||'%' and length(gl_freevalue.valuecode)=10 and bd_accsubj.subjcode like '2123%' and gl_voucher.discardflag='N' and gl_detail.pk_systemv not in('gl','TR') and gl_detail.pk_glbook='0001AA10000000004VTQ' group by substr(gl_freevalue.valuecode,1,6), rollup(( gl_freevalue.valuecode , gl_freevalue.valuename )) order by substr(gl_freevalue.valuecode,1,6)
各類稅(使用餘額表)
select bd_accsubj.subjcode,bd_accsubj.dispname, 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發生額" 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 '2171%' or bd_accsubj.subjcode like '2176%' ) and gl_balance.period<>'00' and gl_balance.year in('2012','2013','2014') group by bd_accsubj.subjcode, bd_accsubj.dispname order by bd_accsubj.subjcode
完成每一個公司前100付款客商
select * from ( select TA.*,rank()over(partition by 付款單位 order by 付款總金額 desc) rn from ( select distinct bd_corp.unitcode, bd_corp.unitname as 付款單位, bd_cubasdoc.custcode as 收款單位編碼 ,bd_cubasdoc.custname as 收款單位名稱, sum(arap_djfb.bbye) over(partition by bd_corp.unitcode,bd_cubasdoc.custcode )as 付款總金額 from bd_cubasdoc,arap_djfb,bd_cumandoc,arap_djzb,bd_corp where arap_djfb.ksbm_cl=bd_cumandoc.pk_cumandoc and bd_cumandoc.pk_cubasdoc= bd_cubasdoc.pk_cubasdoc and arap_djfb.vouchid= arap_djzb.vouchid and bd_corp.pk_corp=arap_djzb.dwbm and arap_djfb.payflag in('1','2') and arap_djfb.dr='0' and length(bd_cubasdoc.custname)>3 and length(bd_cubasdoc.custcode)<>6 and bd_corp.unitcode not in('0100','010101'))TA) where rn<=100
直接order by 的話出現的結果只有鋼結構,所以須要partition 才能出現各個公司的前100
使用partition 必須order by,而且從大到小排練還要desc(默認asc從小到大)
供應商top
select bd_cubasdoc.custcode as 收款單位編碼 ,bd_cubasdoc.custname as 收款單位名稱, sum(arap_djfb.bbye) 收款總金額 from bd_cubasdoc,bd_cumandoc,arap_djfb,arap_djzb where arap_djfb.ksbm_cl=bd_cumandoc.pk_cumandoc and bd_cumandoc.pk_cubasdoc= bd_cubasdoc.pk_cubasdoc and arap_djfb.vouchid= arap_djzb.vouchid and arap_djfb.payflag in('1','2') and arap_djfb.dr='0' and length(bd_cubasdoc.custname)>3 and length(bd_cubasdoc.custcode) not in (6,4) and arap_djzb.djkjnd=2014 group by bd_cubasdoc.custcode,bd_cubasdoc.custname ,arap_djfb.bbye order by sum(arap_djfb.bbye) desc
增長日期:and arap_djzb.djrq between '2015-01-01'and '2015-09-31'
6.27 改進
select bd_cubasdoc.custname as 收款單位名稱, sum(arap_djfb.bbye) 收款總金額 from bd_cubasdoc,bd_cumandoc,arap_djfb,arap_djzb where arap_djfb.ksbm_cl=bd_cumandoc.pk_cumandoc and bd_cumandoc.pk_cubasdoc= bd_cubasdoc.pk_cubasdoc and arap_djfb.vouchid= arap_djzb.vouchid and arap_djfb.payflag in('1','2') and arap_djfb.dr='0' and length(bd_cubasdoc.custname)>3 and length(bd_cubasdoc.custcode) not in (6,4) and arap_djzb.djrq between '2016-01-01'and '2016-03-31' group by bd_cubasdoc.custname order by sum(arap_djfb.bbye) desc
2016-12-14 16:39:47
由於8.6號升級NC5.7,djzb失效,只能取委託付款的
select m.company_r,sum(m.totalamount) from fts_newpayment m where m.billdate between '2016-01-01'and '2016-09-30' and m.netpaystatus=0 group by m.company_r order by sum(m.totalamount) desc
甲方top
select v.def1, gl_freevalue.valuecode, gl_freevalue.valuename, sum( case when gl_detail.prepareddatev between '2016-01-01'and '2016-03-31' then gl_detail.creditamount else 0 end) "本年收款" from gl_detail, bd_accsubj, gl_freevalue,gl_voucher,bd_jobbasfil v where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.assid=gl_freevalue.freevalueid and gl_detail.pk_voucher=gl_voucher.pk_voucher and gl_freevalue.valuecode=v.jobcode and gl_detail.dr = '0' and v.jobcode like '01%' and length(gl_freevalue.valuecode)=10 and (bd_accsubj.subjcode like '2123%')--工程施工總包二級明細 and gl_voucher.discardflag='N'--不能是做廢的憑證 and gl_detail.pk_systemv not in('gl','TR') --去除gl(小寫 期初),大寫手工錄入,TR自定義結轉 group by v.def1, valuecode,valuename order by sum( case when gl_detail.prepareddatev between '2016-01-01'and '2016-03-31' then gl_detail.creditamount else 0 end) desc
甲方須要bd_jobmnfil的def1
真正作的時候select和group去掉 valuecode,valuename,由於有可能一個甲方有好幾個和建工合做的項目
2017-05-05 15:36:01 客商top
select d.custname,sum(c2.local) from cmp_detail c, bd_cubasdoc d, cmp_settlement c2 where c.pk_cubasdoc = d.pk_cubasdoc and c.pk_settlement = c2.pk_settlement --and c.pk_account = bd.pk_bankaccbas --and c.pk_corp = '1038' and c.billdate between '2016-01-01' and '2016-12-31' and c.dr = '0' and c.busilineno = 0 -- 0 是第一行 and c.settlestatus in('5','1') group by d.custname order by 2 desc
2016-10-17 16:19:26
NC 升級57後單據變位arap_djfb_old,arap_djzb_old
勞務收入明細 2016.3.7
select bd_glorgbook.glorgbookcode, bd_glorgbook.glorgbookname,gl_detail.prepareddatev 制單日期, gl_detail.explanation, gl_voucher.no 憑證號, bd_accsubj.dispname, gl_detail.creditamount 工程款 from gl_detail, bd_accsubj, bd_glorgbook, gl_voucher where gl_detail.pk_accsubj = bd_accsubj.pk_accsubj and gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.pk_voucher = gl_voucher.pk_voucher and gl_detail.dr = '0' and gl_detail.periodv<>'00' and gl_detail.yearv= '2015' and bd_glorgbook.glorgbookcode like '03%01-0001' and bd_accsubj.subjcode like '2123%' and gl_detail.creditamount<>0 -- and (gl_voucher.no='263' or gl_voucher.no='207') --and bd_accsubj.subjcode like '150103%' order by bd_glorgbook.glorgbookcode,gl_detail.prepareddatev
轉
Oracle中rank() over, dense_rank(), row_number() 的區別
假設如今有一張學生表student,學生表中有姓名、分數、課程編號,如今我須要按照課程對學生的成績進行排序。
select * from student
1. rank over ()能夠實現對學生排名,特色是成績相同的兩名是並列,以下1 2 2 4 5
select name,
course,
rank() over(partition by course order by score desc) as rank
from student;
2. dense_rank()和rank over()很像,但學生成績並列後並不會空出並列所佔的名次,以下1 2 2 3 4
select name,
course,
dense_rank() over(partition by course order by score desc) as rank
from student;
3. row_number這個函數不須要考慮是否並列,那怕根據條件查詢出來的數值相同也會進行連續排名
select name,
course,
row_number() over(partition by course order by score desc) as rank
from student;
答疑:
1. partition by用於給結果集進行分區。
2. partition by和group by有何區別?
partition by只是將原始數據進行名次排列(記錄數不變)
group by是對原始數據進行聚合統計(記錄數可能變少, 每組返回一條)
3. 使用rank over()的時候,空值是最大的,若是排序字段爲null, 可能形成null字段排在最前面,影響排序結果。
能夠這樣: rank over(partition by course order by score desc nulls last)