表a
date123 value
-----------------------
2007-07-05 1
2007-07-05 2
现在要求列出 2007-07-01到 2007-07-05的所有value的和
结果应该是
-------------------------
2007-7-1 0
2007-7-2 0
2007-7-3 0
2007-7-4 0
2007-7-5 3
但是怎么才能把前4行查询出来啊 表中没有这些天的? 帮忙啊

最新回复
fdc1012 (2008-7-21 10:12:41)
redneck_he (2008-7-21 10:30:13)
select b.mdate,sum(nvl(a.value,0)) from
(select to_char(date123,'yyyy-mm-dd') date123,value from t1) a,
(select to_char(to_date('2007-01-01','yyyy-mm-dd') + rownum,'yyyy-mm-dd') mdate
from dual connect by rownum < 10) b
where b.mdate = a.date123(+)
group by b.mdate
如果你的date123是字符型,就没有必要再转换.
select b.mdate,sum(nvl(a.value,0)) from t1 a,
(select to_char(to_date('2007-01-01','yyyy-mm-dd') + rownum,'yyyy-mm-dd') mdate
from dual connect by rownum < 10) b
where b.mdate = a.date123(+)
group by b.mdate
sieper (2008-7-21 10:36:06)
apollofeier (2008-7-21 11:19:12)