• Welcome to Journal web site.

我是 PHP 程序员

- 开发无止境 -

Next
Prev

(8条消息) 【求SQL语句】MySql数据库中字段值相加的问题-CSDN论坛

Data: 2018-03-07 01:28:33Form: JournalClick: 6

(8条消息) 【求SQL语句】MySql数据库中字段值相加的问题-CSDN论坛

   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 ''

 

select userid,sum(money) from er where er.date between '2010-10-01' and '2010-11-10' group by userid 
select sum(money)
from 如上表
where userId=1
and date between '2011-08-09' and '2011-08-18'
Name:
<提交>