日期:2014-05-16 浏览次数:20972 次
select a.公司 ,nvl(sum(b.入库数),0) 入库数,nvl(sum(a.出库数),0) 出库数,t1.时间 from (select 时间 from a union select 时间 from b) t1 left join a on t1.时间=a.时间 left join b on t1.时间=b.时间 where a.公司=b.公司 group by a.公司,t1.时间 order by a.公司,t1.时间 desc
------解决方案--------------------
select 公司,
sum(入库数),
sum(出库数),
时间
from (
select a.公司 as 公司,
0 as 入库数,
decode (a.是否出库, '1', 1, 0)
as 出库数,
a.时间 as 时间
from a
union all
select b.公司 as 公司,
decode (b.是否入库, '1', 1, 0)
as 入库数,
0 as 出库数,
b.时间 as 时间
from b
)
group by 公司,时间
order by 公司,时间