建工发债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_glorgbookwhere gl_balance.pk_accsubj = bd_accsubj.pk_accsubjand bd_glorgbook.pk_glorgbook = gl_balance.pk_glorgbookand 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_glorgbookwhere gl_balance.pk_accsubj = bd_accsubj.pk_accsubjand bd_glorgbook.pk_glorgbook = gl_balance.pk_glorgbookand 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 bwhere a.scode=b.subjcodeand 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_glorgbookwhere gl_balance.pk_accsubj = bd_accsubj.pk_accsubjand bd_glorgbook.pk_glorgbook = gl_balance.pk_glorgbookand 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科目余額和投標報表數字不一致)
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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0'and gl_detail.yearv='2013'and bd_glorgbook.glorgbookcode = '010201-0001'and length(gl_freevalue.valuecode)=10and (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
審計要的項目成本二級明細
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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0'and gl_detail.yearv='2013'and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10and (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),subjnameorder by glorgbookcode,valuecode,substr(subjcode,1,8)?三年合一
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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10and (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) ,subjnameorder by glorgbookcode,valuecode,substr(subjcode,1,8)?2016-11-02 10:22:30
施書云要管理費用各公司
select bd_glorgbook.glorgbookname, gl_detail.prepareddatev 制單日期, gl_detail.explanation,bd_accsubj.dispname,gl_detail.debitamount 借方,gl_detail.creditamount 貸方, gl_voucher.no 憑證號from bd_accsubjjoin gl_detailon gl_detail.pk_accsubj = bd_accsubj.pk_accsubjjoin bd_glorgbookon bd_glorgbook.pk_glorgbook = bd_accsubj.pk_glorgbookjoin gl_voucheron gl_detail.pk_voucher = gl_voucher.pk_voucherwhere 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.pk_voucher=gl_voucher.pk_voucherand 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10and (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,valuenameorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '01%-0001' and length(gl_freevalue.valuecode)=10and (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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0'and bd_glorgbook.glorgbookcode like '0104%-0001'and length(gl_freevalue.valuecode)=10and (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.valuenameorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0'and bd_glorgbook.glorgbookcode like '0104%-0001'and length(gl_freevalue.valuecode)=10and (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.valuenameorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0'and bd_glorgbook.glorgbookcode like '0104%-0001'and length(gl_freevalue.valuecode)=10and (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.valuenameorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '03%-0001' and length(gl_freevalue.valuecode)=10and (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<>0order 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0' and bd_glorgbook.glorgbookcode like '03%01-0001' and length(gl_freevalue.valuecode)=10and (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 bwhere a.valuecode=b.jobcodeorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbookand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_detail.dr = '0'and bd_glorgbook.glorgbookcode = '011601-0001'and length(gl_freevalue.valuecode)=10and (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.valuenameorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_corp = bd_corp.pk_corpand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand 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)=10and 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_glorgbookwhere gl_balance.pk_accsubj = bd_accsubj.pk_accsubjand bd_glorgbook.pk_glorgbook = gl_balance.pk_glorgbookand 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.dispnameorder 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.vouchidand 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.vouchidand 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=0group 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 vwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.assid=gl_freevalue.freevalueidand gl_detail.pk_voucher=gl_voucher.pk_voucherand gl_freevalue.valuecode=v.jobcodeand gl_detail.dr = '0' and v.jobcode like '01%' and length(gl_freevalue.valuecode)=10and (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,valuenameorder 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) fromcmp_detail c, bd_cubasdoc d, cmp_settlement c2where 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.custnameorder 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_voucherwhere gl_detail.pk_accsubj = bd_accsubj.pk_accsubjand gl_detail.pk_glorgbook = bd_glorgbook.pk_glorgbook and gl_detail.pk_voucher = gl_voucher.pk_voucherand 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)
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
- 上一篇: 去除tableview中每个cell的分
- 下一篇: linux安装和配置 mysql、red