一个时间段内求和的SQL,在线求解
南山行者 2015-06-23 11:23:26 我想在想把过去一个时间段(比如10天)内的数据一个合计,
id total time
1 100 2015/01/01
2 101 2015/01/05
3 83 2015/01/05
4 106 2015/01/08
5 99 2015/01/19
6 190 2015/01/21
7 60 2015/01/22
如果我这样写
select
sum(total)
from tt
where time>= trunc(to_date('2015/01/10 00:00' ,'yyyy/MM/dd HH24:mi:ss') - 10)
and time< trunc(to_date('2015/01/10 00:00' ,'yyyy/MM/dd HH24:mi:ss'))
group by time
这样写的话,数据就是
100
184
83
但我需要的是不管有没有这一天,都要算上,
100
0
0
0
184
0
0
106
0
0
但是这个SQL语句怎么写呢