DROP TABLE #TEMP
select ctype,case month(ctime) when month(getdate()) then sum(cnum) end as '本月数量', case month(ctime) when month(getdate())-1 then sum(cnum) end as '上月数量' into #temp from ctest group by ctype,month(ctime)
select ctype,sum(本月数量) AS 本月数量,SUM(上月数量) AS 上月数量 from #temp group by ctype