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 .

解决方案 »

  1.   

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

  2.   

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

  3.   

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

  4.   

    select sum(money)
    from 如上表
    where userId=1
    and date between '2011-08-09' and '2011-08-18'