博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[补充工程统计case]科技活动经费sql2014
阅读量:5153 次
发布时间:2019-06-13

本文共 5568 字,大约阅读时间需要 18 分钟。

select bd_glorgbook.glorgbookcode,bd_glorgbook.glorgbookname,       gl_detail.explanation,       bd_accsubj.dispname,       gl_detail.debitamount 借方,       gl_detail.creditamount 贷方,       gl_detail.prepareddatev 制单日期,       gl_voucher.no 凭证号,       wmsys.wm_concat(gl_freevalue.valuecode) valuecode,       wmsys.wm_concat(gl_freevalue.valuename) valuename,       gl_detail.pk_systemv,       gl_detail.detailindex  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  left join gl_freevalue    on gl_detail.assid = gl_freevalue.freevalueid where gl_detail.dr = '0' and ( bd_accsubj.subjcode like  '4104010508%'or bd_accsubj.subjcode like  '550212%')       and bd_glorgbook.glorgbookcode like '01%-0001'   and gl_detail.yearv = '2013' /* and gl_detail.creditamount ='0'*/   and gl_detail.explanation<>'期初'   and gl_detail.debitamount<>0  /* and gl_detail.explanation='付财大凤凰楼项目人工费(洪荣森)'*/--and bd_accsubj.subjcode like '150103%' group by bd_glorgbook.glorgbookcode,bd_glorgbook.glorgbookname, gl_detail.explanation,          bd_accsubj.dispname,          gl_detail.creditamount,          gl_detail.debitamount,          gl_detail.prepareddatev,          gl_voucher.no,          gl_detail.pk_systemv,          gl_detail.detailindex order by  bd_glorgbook.glorgbookcode, bd_accsubj.dispname,gl_detail.prepareddatev, gl_voucher.no

 发给建行的

select-- bd_glorgbook.glorgbookcode,--bd_glorgbook.glorgbookname,--gl_detail.prepareddatev 制单日期,    -- gl_voucher.no 凭证号,    -- gl_detail.explanation,     gl_detail.yearv,       bd_accsubj.dispname,       sum(gl_detail.debitamount)   金额      -- 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.debitamount<>0   and gl_detail.yearv in ('2011','2012','2013')   --and bd_glorgbook.glorgbookcode = '010201-0001'   --and (gl_voucher.no='263' or gl_voucher.no='207')   and (bd_accsubj.subjcode like '550212%' or bd_accsubj.subjcode like '4104010508%')   and bd_glorgbook.glorgbookcode like '01%'    group by   gl_detail.yearv,bd_accsubj.dispname order by  gl_detail.yearv,bd_accsubj.dispname

下面是rollup安装分公司小计

select  bd_glorgbook.glorgbookcode,           nvl(replace(bd_glorgbook.glorgbookname,'集团基准账薄',''),'小计')公司名称, --从萝卜那里学习                      bd_accsubj.subjcode,bd_accsubj.subjname,           sum( case when gl_balance.year= '2010' then  gl_balance.debitamount else 0 end) "2010发生额",           sum( case when gl_balance.year= '2011' then  gl_balance.debitamount else 0 end) "2011发生额",           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%' or bd_accsubj.subjcode like '5503%')       and gl_balance.period<>'00'       and gl_balance.year in('2010','2011','2012')      group by bd_glorgbook.glorgbookcode,  rollup((bd_accsubj.subjcode,bd_accsubj.subjname , bd_glorgbook.glorgbookname))          order by bd_glorgbook.glorgbookcode,  bd_accsubj.subjcode

2014.9.10 更新

统计各个公司2010-2014费用

期间发生了问题,sum的时候里面不能是数字和汉字的组合,否则

 

单位取到万

select glorgbookcode,公司名称,( case substr(subjcode,1,4) when '5502' then '管理费用'  when '5503' then '财务费用'    when '5201' then '投资收益'      when '5301' then '营业外收入'        else    '营业外支出' end )"会计科目",round(sum(A)/10000,2)"2010发生额",round(sum(B)/10000,2) "2011发生额",round(sum(C)/10000,2)"2012发生额",round(sum(D)/10000,2) "2013发生额",round(sum(E)/10000,2) "2014发生额" from (  select  bd_glorgbook.glorgbookcode,           nvl(replace(bd_glorgbook.glorgbookname,'集团基准账薄',''),'小计')公司名称, --从萝卜那里学习                      bd_accsubj.subjcode,bd_accsubj.subjname,           sum( case when gl_balance.year= '2010' then  gl_balance.debitamount else 0 end) A,           sum( case when gl_balance.year= '2011' then  gl_balance.debitamount else 0 end)B,           sum( case when gl_balance.year= '2012' then  gl_balance.debitamount else 0 end) C,             sum( case when gl_balance.year= '2013' then  gl_balance.debitamount else 0 end) D,           sum( case when gl_balance.year= '2014' then  gl_balance.debitamount else 0 end) E                              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%' --管理费用       or bd_accsubj.subjcode like '5503%'  -- 财务费用       or bd_accsubj.subjcode like '5201%' --投资收益       or bd_accsubj.subjcode like '5301%' --营业外收入       or bd_accsubj.subjcode like '5601%' --营业外支出       )       and gl_balance.period<>'00'       and gl_balance.year in('2010','2011','2012','2013','2014')      group by bd_glorgbook.glorgbookcode,  bd_accsubj.subjcode,bd_accsubj.subjname , bd_glorgbook.glorgbookname          order by bd_glorgbook.glorgbookcode,  bd_accsubj.subjcode)    group by glorgbookcode,公司名称,substr(subjcode,1,4)    order by glorgbookcode,substr(subjcode,1,4)

 

转载于:https://www.cnblogs.com/sumsen/p/3670203.html

你可能感兴趣的文章
Python核心编程——多线程threading和队列
查看>>
Program exited with code **** 相关解释
查看>>
植物大战僵尸中文年度版
查看>>
26、linux 几个C函数,nanosleep,lstat,unlink
查看>>
投标项目的脚本练习2
查看>>
201521123107 《Java程序设计》第9周学习总结
查看>>
runtime的基本应用
查看>>
关于scrollTop的那些事
查看>>
Caroline--chochukmo
查看>>
算法导论笔记 第8章 线性时间排序
查看>>
利用jquery的contains实现搜索功能
查看>>
Xcode 6.2 beta 3 太难下载!下载了,不敢独享
查看>>
并发编程
查看>>
Bootstrap
查看>>
C语言错误: HEAP CORRUPTION DETECTED
查看>>
【Java基础】Java类的加载和对象创建流程的详细分析
查看>>
2018-2019-1 20165231《信息安全系统设计基础》第二周学习总结
查看>>
iOS之文本属性Attributes的使用
查看>>
从.Net版本演变看String和StringBuilder性能之争
查看>>
Excel操作 Microsoft.Office.Interop.Excel.dll的使用
查看>>