- 开发无止境 -
Data: 2018-03-07 01:28:33Form: JournalClick: 6
userId money date
1 500 2011-08-09
2 100 2011-08-12
1 200 2011-08-17
1 300 2011-08-18
如上表:
求MySql语句一条, 要求:在日期范围内,相同userId的money相加,
例如: 2011-08-09 ~ 2011-08-18 内,userId 为 1 的用户总的 money 相加为 1000 .
select userId ,sum(money) from tt where `date` between '2011-08-09' and '2011-08-18'
group by userId
select sum(userid),sum(money) from tb where date between '' and ''