日期:2014-05-17 浏览次数:20746 次
select projectid,sum(downloadIncome),sum(adIncome),time from ( select projectid,downloadIncome ,0 as adIncome , time from A表 union all select projectid ,0, adIncome ,time from B表 ) t group by projectid,time order by time
------解决方案--------------------
--还是写一个吧,2楼少关联了一个条件
with a as(
select 1 projectid, 100 downloadincome, date'2010-04-10' time from dual union all
select 1 projectid, 200 downloadincome, date'2010-04-11' time from dual),
b as(
select 1 projectid, 100 adincome, date'2010-04-10' time from dual union all
select 1 projectid, 300 adincome, date'2010-04-12' time from dual)
SELECT nvl(a.projectid, b.projectid) projectid,
nvl(a.downloadincome, 0) downloadincome,
nvl(b.adincome, 0) adincome,
nvl(a.time, b.time) TIME
FROM a
FULL OUTER JOIN b
ON (a.projectid = b.projectid AND a.time = b.time);