我创建了一个消费表,每个月(month)每天(day)都有消费金额(money),怎么样把每天的金额查询出来相加,我要算出一个月总的消费金额赋值到其他地方。

解决方案 »

  1.   

    select sum(money)
    from tb
    where month=''
      

  2.   

    select sum(money),day
    from tb
    group by day
      

  3.   

    是这样吗:--如果有month这个字段,计算每个月的总消费金额
    select month,
           sum(money)
    from tb
    group month
      

  4.   

    如果没有月,可以这样,试试:
    --计算每个月的总消费金额,比如计算8月份的数据select sum(money)
    from tb
    where day >='2013-08-01'
      and day <='2013-08-31'
      

  5.   


    select sum(money),day
    from tb
    group by day
      

  6.   

    select [month],[day],
    amt=(select SUM(消费金额) from tb b where b.[month]=a.[month] and b.[day]<=a.[day])
    from tb a
      

  7.   

    我直接用sum再后面跟year month的条件做好了,把当前月的所有money值通过sum加起来就行了,是我想多了。