我正在试着从oracle developer那里得到一个结果。我需要连接3个表的日期,输出应该是:
Date sum count num
2012-10-01 5000 30 15
2012-10-02 0 0 0
2012-10-03 60 150 350
2012-10-04 20 200 300
2012-10-05 1000 100 200
2012-10-06 1500 109 400输入范围为2012-10-01 - 2012-10-06。如果它找不到数据,请在所有其他列中使用0作为日期
在进阶时谢谢。
发布于 2012-10-10 20:15:36
您应该生成所有日期,然后在日期上将表连接起来。
类似于(我使用了两个表):
select date_col, nvl(sum(t1.val),0) + nvl(sum(t2.val,0)) as sum
from
(select to_date('01-OCT-2012','dd-mon-yyyy') + level - 1 as date_col
from dual connect by level <= to_date('06-OCT-2099','dd-mon-yyyy') - to_date('01-OCT-2012','dd-mon-yyyy') + 1
) d
left join table1 t1 on (t1.date_column = d.date_col)
left join table2 t2 on (some_t1_t2_join_condition and t2.date_column = d.date_col);https://stackoverflow.com/questions/12818942
复制相似问题