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

laughing__ 2011-08-19 02:43:56
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 .

...全文
434 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2011-08-19
  • 打赏
  • 举报
回复
select sum(money)
from 如上表
where userId=1
and date between '2011-08-09' and '2011-08-18'
sunjiaohunbegfly 2011-08-19
  • 打赏
  • 举报
回复
select userid,sum(money) from er where er.date between '2010-10-01' and '2010-11-10' group by userid
rucypli 2011-08-19
  • 打赏
  • 举报
回复
select sum(userid),sum(money) from tb where date between '' and ''
wwwwb 2011-08-19
  • 打赏
  • 举报
回复
select userId ,sum(money) from tt where `date` between '2011-08-09' and '2011-08-18'
group by userId

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧