分组统计
表结构如下:
需求:
按照groupid,Gr_time 分组计算 num 之和并且按照
显示结果:
groupid Gr_time Num
110 2013-01 20
110 2012-12 50
------解决方案--------------------
select groupid,left(convert(varchar,Gr_time,23),7)Gr_time,sum(Num)Num from 表名
group by groupid,left(convert(varchar,Gr_time,23),7)
------解决方案--------------------SELECT groupid ,
LEFT(Gr_time, 7) Gr_time ,
SUM(num) num
FROM TB
GROUP BY groupid ,
LEFT(Gr_time, 7)
------解决方案--------------------select Groupid ,left(cast(Gr_time as varchar(25)),7)as Gr_time,sum(num)as Num
from tbl
group by groupid,left(cast(Gr_time as varchar(25)),7)