暂时
select bd_glorgbook.glorgbookcode,
nvl(replace(bd_glorgbook.glorgbookname,‘集团基准账薄‘,‘‘),‘小计‘)公司名称, --从萝卜那里学习
bd_accsubj.subjcode,bd_accsubj.subjname,
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发生额"
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((bd_accsubj.subjcode,bd_accsubj.subjname , bd_glorgbook.glorgbookname))
order by bd_glorgbook.glorgbookcode, bd_accsubj.subjcode