sql查询出最近一周内每天的总数

表table

id   date            money
1    2011-06-02      11
2    2011-06-03      8
3    2011-06-04      7
4    2011-06-04      8
5    2011-06-05      10
6    2011-06-07      6
7    2011-06-08      6
8    2011-06-09      16

求sql 能查询出最近一周内 每一天的money总数

结果

id   date            money
1    2011-06-03      8
2    2011-06-04      15
3    2011-06-05      10
4    2011-06-06      0
5    2011-06-07      6
6    2011-06-08      6
7    2011-06-09      16

参考:

select  date,sum(money) as money
from tab
where date>= convert(varchar(10),dateadd(day,-7,getdate()),120)
group by date

 

赞(0)
未经允许不得转载:TaKaSa » sql查询出最近一周内每天的总数

相关推荐