110,533
社区成员
发帖
与我相关
我的任务
分享
declare @s nvarchar(max)
Select @s=isnull(@s+',','')+quotename(入库期间) from Product GROUP BY 入库期间 order by 入库期间 DESC
exec('select [产品名],'+@s+' from (
select 产品名,入库期间,[总入库数量]=sum([入库数量])over(partition by [产品名],[入库期间]) from Product) a
pivot (MAX([总入库数量]) for [入库期间] in('+@s+'))b')