表中的1月2月...12月数据是使用sum 合计出来的,我想把这个1月到12月作为横轴数据,这样折线图显示的是 办事处某一种产品12个月份销量变化。 但是现在遇到问题,这里只能选择一个字段作为分类,和我需要的不一样。 select a.BanshichuName,b.ProductName, sum(case when MONTH(a.EnterDate)=1 then ProductCount else 0 end ) as 'one', sum(case when MONTH(a.EnterDate)=2 then ProductCount else 0 end ) as 'two', sum(case when MONTH(a.EnterDate)=3 then ProductCount else 0 end ) as 'three', sum(case when MONTH(a.EnterDate)=4 then ProductCount else 0 end ) as 'four', sum(case when MONTH(a.EnterDate)=5 then ProductCount else 0 end ) as 'five', sum(case when MONTH(a.EnterDate)=6 then ProductCount else 0 end ) as 'six', sum(case when MONTH(a.EnterDate)=7 then ProductCount else 0 end ) as 'seven', sum(case when MONTH(a.EnterDate)=8 then ProductCount else 0 end ) as 'eight', sum(case when MONTH(a.EnterDate)=9 then ProductCount else 0 end ) as 'nine', sum(case when MONTH(a.EnterDate)=10 then ProductCount else 0 end ) as 'ten', sum(case when MONTH(a.EnterDate)=11 then ProductCount else 0 end ) as 'eleven', sum(case when MONTH(a.EnterDate)=12 then ProductCount else 0 end ) as 'twelve' from dbo.StorageOutSell a inner join dbo.StorageOutSellDetail b on a.StorageInOtherID=b.StorageInOtherID inner join Product c on c.Code=b.ProductNo where b.ProductName ='"+chanpinmingcheng+"'"+ group by b.ProductNo,b.ProductName,b.UnitPrice,c.Categories,b.UnitID,a.BanshichuName)T1 这是我的SQL语句,可能有点麻烦。我的一点看法是 我这里的sql语句要改一下,将12个月份查出来合并成一个字段,这样才能在分类中设置。但是这些月份都是我as出来的,没招了,问一下大家怎么解决这种问题。 |