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 = ''
and ( bd_accsubj.subjcode like '4104010508%'or bd_accsubj.subjcode like '550212%') and bd_glorgbook.glorgbookcode like '01%-0001'
and gl_detail.yearv = ''
/* 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 = ''
and gl_detail.periodv<>''
and gl_detail.debitamount<>0
and gl_detail.yearv in ('','','')
--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= '' then gl_balance.debitamount else 0 end) "2010发生额",
sum( case when gl_balance.year= '' then gl_balance.debitamount else 0 end) "2011发生额",
sum( case when gl_balance.year= '' 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<>''
and gl_balance.year in('','','')
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 '' then '管理费用'
when '' then '财务费用'
when '' then '投资收益'
when '' 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= '' then gl_balance.debitamount else 0 end) A,
sum( case when gl_balance.year= '' then gl_balance.debitamount else 0 end)B,
sum( case when gl_balance.year= '' then gl_balance.debitamount else 0 end) C,
sum( case when gl_balance.year= '' then gl_balance.debitamount else 0 end) D,
sum( case when gl_balance.year= '' 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<>''
and gl_balance.year in('','','','','')
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)

[补充工程统计case]科技活动经费sql2014的更多相关文章

  1. 大数据学习----day27----hive02------1. 分桶表以及分桶抽样查询 2. 导出数据 3.Hive数据类型 4 逐行运算查询基本语法(group by用法,原理补充) 5.case when(练习题,多表关联)6 排序

    1. 分桶表以及分桶抽样查询 1.1 分桶表 对Hive(Inceptor)表分桶可以将表中记录按分桶键(某个字段对应的的值)的哈希值分散进多个文件中,这些小文件称为桶. 如要按照name属性分为3个 ...

  2. 数据分组、统计 case when then else end

    case when 对表进行条件分组 case简单函数 case   age  when   then select name , sex , age , ( case age /*when 条件成立 ...

  3. 并列统计CASE WHEN

    select sum(case when depart = 'Physical' then 1 else 0 end) PhyTotal, sum(case when depart = 'Chemis ...

  4. javaWeb代码工程统计

    直接放在src/test/java包内运行 /** * 代码行数统计 * @author ThinkGem * @version 2014-7-22 */ public class CodeCount ...

  5. 微软Azure AspNetCore微服务实战第1期【补充2017-09-09活动】

    2017年09月09日,冒着酷暑,我们在(上海徐汇)虹桥路3号港汇中心2座10层组织了一次微软Azure AspNetCore微服务实战活动. 由于前期工作繁忙,活动完成之后,没能及时发布相关信息,特 ...

  6. Android: Intent实现活动之间的交互

    Intent的作用:是Android中各个组件直接交互的一种重要方式,且利用Intent可以启动Activity.Service以及Broadcast Receiver. Intent的创建:显示和隐 ...

  7. 本招聘信息2014年长期有效!杭州派尔科技高薪诚聘android开发(10K-20K),web前端开发(8K-15K),IOS开发(15K-25K)

    杭州派尔科技有限公司发展至今,离不开员工的无私奉献和辛勤耕耘,在努力创造更好成绩的同时,公司也不忘回馈每一位员工的努力与付出.1.全面的绩效考核机制,让发展空间近在眼前!公司力争让每一位员工都了解自己 ...

  8. android switch语句报错:case expressions must be constant expressions

    今天无意中碰见了   case expressions must be constant expressions 的问题 写了一个 switch(item.getItemId()) { case R. ...

  9. (转)Delphi工程文件说明

    1.DPR: Delphi Project文件,包含了Pascal代码.应用系统的工程文件2.PAS: Pascal文件,Pascal单元的源代码,可以是与窗体有关的单元或是独立的单元.3.DFM:D ...

随机推荐

  1. Nginx reopen reload作用及工作过程

    http://www.iigrowing.cn/nginx-reopen-reload-zuo-yong-ji-gong-zuo-guo-cheng.html Nginx reopen reload作 ...

  2. eclise 部署web工程报 There are no resources that can be added or removed from the server.

    该文章转自: http://blog.csdn.net/dw_java08/article/details/7789601 eclise 部署web工程报 There are no resources ...

  3. mongostat 3.2指标详解

    存储引擎:wiredTiger /usr/local/mongodb-3.2.8/bin/mongostat  -uroot -pcEqHuoqiJYhjVpuL --host 127.0.0.1   ...

  4. 特定场景下SQL的优化

    1.大表的数据修改最好分批处理. 1000万行的记录表中删除更新100万行记录,一次只删除或更新5000行数据.每批处理完成后,暂停几秒中,进行同步处理. 2.如何修改大表的表结构. 对表的列的字段类 ...

  5. android使用html+javascript来制作页面

    一般的android界面使用的是XML.但是XML如果要制作很高级的UI,会很复杂.如果使用HTML老进行UI设计就会简单很多. android早就提供了这样的借口. WebView.addJavas ...

  6. 图表控件的学习===》hightChart 和 Chartjs的使用

    hightChart : 比较旧的图表控件   商业需要授权 Chartjs 免费开源 刚开始使用了下 hightchart 然后参考示例 建了对应的参数配置的类, 也顺利的集合到后台动态传输.  后 ...

  7. C# List和String互相转换

    List转字符串,用逗号隔开 List<string> list = new List<string>();list.Add("a");list.Add(& ...

  8. JavaScript基础--内部类(九)

    js的内部类javascript 中本身提供一些,可以直接使用的类,这种类就是内部类,主要有:ObjectArrayMathBooleanStringRegExpDateNumber 1.内部类分类从 ...

  9. Win7下通过eclipse远程连接CDH集群来执行相应的程序以及错误说明

    最近尝试这用用eclipse连接CDH的集群,由于之前尝试过很多次都没连上,有一次发现Cloudera Manager是将连接的端口修改了,所以才导致连接不上CDH的集群,之前Apache hadoo ...

  10. 2-legged oauth & 3-legged oauth

    3-legged oauth resource owner, client, server. resource owner 给client访问权限去访问resource owner在server上的r ...