日期:2014-05-18  浏览次数:20683 次

sql分组求和
如题:
表结构:[entid] varchar,[smstotal] int,[smscharge] int,[smsentertime] datetime
要根据entid分组求smstotal,smscharge这两列的和,sql语句是这样的:
select entid,sum(smstotal),sum(smscharge) from qmsg_addsmsmmslog group by entid
但是我要限定时间(smsentertime)要怎么写啊?

------解决方案--------------------
select entid,sum(smstotal),sum(smscharge) from qmsg_addsmsmmslog where (时间的条件) group by entid
------解决方案--------------------
select entid,sum(smstotal),sum(smscharge) from qmsg_addsmsmmslog where smsentertime = ... group by entid

select entid,sum(smstotal),sum(smscharge) from qmsg_addsmsmmslog where smsentertime between ... and ... group by entid
------解决方案--------------------
SQL code

select entid,sum(smstotal),sum(smscharge) from qmsg_addsmsmmslog 
where smsentertime >=? --加个where
group by entid

------解决方案--------------------
加个时间字段的条件