数据库问题

QQ图片20181130142835.png

select 

sum(GBAPYC/100), --年初数,

sum(GBAN/100), --月份数合计,

sum(GBAPYC/100+GBAN/100), --期末数,

trim(GBOBJ)||trim(GBSUB) GBOBJGBSUB

--trim(GBOBJ)||trim(GBSUB)

from 

(

select GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN01 GBAN, 1 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN02 GBAN, 2 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN03 GBAN, 3 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN04 GBAN, 4 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN05 GBAN, 5 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN06 GBAN, 6 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN07 GBAN, 7 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN08 GBAN, 8 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN09 GBAN, 9 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN10 GBAN, 10 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN11 GBAN, 11 m FROM proddta.f0902

union all

select 0 GBAPYC,GBOBJ,GBSUB,GBAID,GBCTRY,GBFY,GBCO,GBAN12 GBAN, 12 m FROM proddta.f0902

)

where GBCTRY = '${GBCTRY}' 

and GBFY = '${GBFY}' 

and GBCO = '${GBCO}'

and m<='${GBAN}' 

--group by trim(GBOBJ)

order by 4


FineReport baijiajun89757 发布于 2018-11-30 14:29
1min目标场景问卷 立即参与
回答问题
悬赏:4 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
axingLv6专家互助
发布于2018-11-30 14:35

后面要加上group by trim(GBOBJ)||trim(GBSUB)

  • 2关注人数
  • 348浏览人数
  • 最后回答于:2018-11-30 14:35
    请选择关闭问题的原因
    确定 取消
    返回顶部