一个日期分段的问题
有一张销售表
现在我筛选时间regtime为2012-12-23至2013-1-14,然后我要统计这两个月销量,用SQL语句处理为2012-12,2013-1,并将Amount内的数量合计到相应的这两个月中,这个SQL语句怎么写
------解决方案--------------------select brand,
sum(amount)amount,
stuff((select ','+convert(varchar(7),regtime,120)
from tb
where brand=t.brand
for xml path('')),1,1,'')
from tb t
group by brand
------解决方案--------------------
select SUM(amount) total,CONVERT(varchar(7),regtime) [month] from tab
where regtime between '2012-12-23' and '2013-01-14'
group by CONVERT(varchar(7),regtime)
------解决方案--------------------select CONVERT(varchar(7),regtime,120) MM,brand,SUM(amount) total from tb
where regtime between '2012-12-23' and '2013-01-14'
group by CONVERT(varchar(7),regtime,120),brand