求助大佬,帮看看怎么把这两个语句合为一条语句
sql吧
全部回复
仅看楼主
level 2
明日猫猫 楼主
第一条:
select col_1 as 项目名称,col_2 as 本期数,col_3 as 上年同期,col_6 as 关联标识,
case when col_8 ='' then '610010' else col_8 end as 规范名称,col_7 as 说明,
row_number()
from 投资收益
where (col_2<>'0.00' or col_3<>'0.00')
and (col_2<>'' or col_3<>'')
and (col_2<>'0' or col_3<>'0')
第二条:
with a as (select col_1 ,col_6 ,col_8,col_7,sum(col_2) as sum_issue ,sum(col_3) as sum_previous from 投资收益)
select col_1 as 项目名称,col_6 as 关联标识,
case when col_8 ='' then '610010' else col_8 end as 规范名称,col_7 as 说明,
case when col_2='' then (select sum_issue from a ) else col_2 end as 本期叔,
case when col_3='' then (select sum_previous from a ) else col_3 end as 上年同期
from 投资收益合计
where exists (select 1 from 投资收益合计)
union all
select col_1 ,col_6 ,sum_issue,sum_previous,col_8,col_7
from a
where not exists (select 1 from 投资收益合计)
2018年10月29日 12点10分 1
1