+ -
当前位置:首页 → 问答吧 → 【求SQL语句】MySql数据库中字段值相加的问题

【求SQL语句】MySql数据库中字段值相加的问题

时间:2011-08-19

来源:互联网

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 .

作者: laughing__   发布时间: 2011-08-19

select userId ,sum(money) from tt where `date` between '2011-08-09' and '2011-08-18'
group by userId

作者: wwwwb   发布时间: 2011-08-19

SQL code
select sum(userid),sum(money) from tb where date between '' and ''

作者: rucypli   发布时间: 2011-08-19

select userid,sum(money) from er where er.date between '2010-10-01' and '2010-11-10' group by userid

作者: sunjiaohunbegfly   发布时间: 2011-08-19