3,491
社区成员
发帖
与我相关
我的任务
分享
select a.单位名称,
'收入 '||sum(decode(to_char(a.收入日期,'mm'),'01',a.收入))||' '||'销售 '||sum(decode(to_char(b.销售日期,'mm'),'01',b.销售)) "一月",
....
'收入 '||sum(decode(to_char(a.收入日期,'mm'),'12',a.收入))||' '||'销售 '||sum(decode(to_char(b.销售日期,'mm'),'12',b.销售)) "十二月"
from shouru a,xiaoshou b
where a.单位名称=b.单位名称 and to_char(a.收入日期,'mm')=to_char(b.销售日期,'mm')
group by a.单位名称
select a.单位名称
,sum(case when to_char(a.收入日期,'mm')='01' then a.收入 end) 一月收入
,sum(case when to_char(b.销售日期,'mm')='01' then b.销售 end) 一月销售
...
from shouru a,xiaoshou b
where a.单位名称=b.单位名称 and to_char(a.收入日期,'yyyy')='2010' and to_char(b.销售日期,'yyyy')='2010'
group by a.单位名称
;
单位名称 一月 二月 。。。。。。。 十一月 十二月
收入 销售 收入 销售 收入 销售 收入 销售
select a.单位名称
,sum(case when a.收入日期='一月' then a.收入 end) 一月收入
,sum(case when b.销售日期='一月' then b.销售 end) 一月销售
,sum(case when a.收入日期='二月' then a.收入 end) 二月收入
,sum(case when b.销售日期='二月' then b.销售 end) 二月销售
,sum(case when a.收入日期='三月' then a.收入 end) 三月收入
,sum(case when b.销售日期='三月' then b.销售 end) 三月销售
...
from shouru a,xiaoshou b
where a.单位名称=b.单位名称
group by a.单位名称
;