简单的sql运用,求指导 我创建了一个消费表,每个月(month)每天(day)都有消费金额(money),怎么样把每天的金额查询出来相加,我要算出一个月总的消费金额赋值到其他地方。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 select sum(money)from tbwhere month='' select sum(money),dayfrom tbgroup by day 是这样吗:--如果有month这个字段,计算每个月的总消费金额select month, sum(money)from tbgroup month 如果没有月,可以这样,试试:--计算每个月的总消费金额,比如计算8月份的数据select sum(money)from tbwhere day >='2013-08-01' and day <='2013-08-31' select sum(money),dayfrom tbgroup by day select [month],[day], amt=(select SUM(消费金额) from tb b where b.[month]=a.[month] and b.[day]<=a.[day])from tb a 我直接用sum再后面跟year month的条件做好了,把当前月的所有money值通过sum加起来就行了,是我想多了。 求指教一个SQL语句怎么写? 求一条SQL更新语句 再问材料出入明细帐 急!!在线等!MSSQL2000如何取消已经设定的作业调度 WIN安装sql2008问题 根据ID相同,将不同列显示在同一行 一个IF的简单问题! 请问,如何在unix下边访问ms sql server数据库呢? 查询排序问题 怎樣在查詢分析器裏面寫測試腳本?測試某個存儲過程? sql批量替换问题 关于分组递增的问题,请指教,谢谢。
from tb
where month=''
from tb
group by day
select month,
sum(money)
from tb
group month
--计算每个月的总消费金额,比如计算8月份的数据select sum(money)
from tb
where day >='2013-08-01'
and day <='2013-08-31'
select sum(money),day
from tb
group by day
amt=(select SUM(消费金额) from tb b where b.[month]=a.[month] and b.[day]<=a.[day])
from tb a