使用新月份数据更新SQL Server Pivot

时间:2016-01-15 19:16:20

标签: sql sql-server database sql-update pivot

我在SQL服务器中有一个数据透视表,我用查询创建。列是月,行是按客户ID,枢轴中的值是每个月的订阅金额的总和。我希望能够每个月使用该月的新数据更新这个数据,但我不确定如何完全重新创建表格。

有没有办法创建一个新列(对于新月)并使用UPDATE用客户的总计订阅金额填充它?

这是我创建表格的查询:

SELECT * INTO [Service Contract Data].[dbo].[Pivot_Results] FROM [Service Contract Data].[dbo].[filtered_data] 
PIVOT (SUM([Service Contract Data].[dbo].[filtered_data].[Subscription Amount])
FOR filtered_data.[Month]
IN([2013-01-01 00:00:00.00],[2013-02-01 00:00:00.00],[2013-03-01 00:00:00.00],[2013-04-01 00:00:00.00],[2013-05-01 00:00:00.00],[2013-06-01 00:00:00.00],[2013-07-01 00:00:00.00],[2013-08-01 00:00:00.00],[2013-09-01 00:00:00.00],[2013-10-01 00:00:00.00],[2013-11-01 00:00:00.00],[2013-12-01 00:00:00.00],[2014-01-01 00:00:00.00],[2014-02-01 00:00:00.00],[2014-03-01 00:00:00.00],[2014-04-01 00:00:00.00],[2014-05-01 00:00:00.00],[2014-06-01 00:00:00.00],[2014-07-01 00:00:00.00],[2014-08-01 00:00:00.00],[2014-09-01 00:00:00.00],[2014-10-01 00:00:00.00],[2014-11-01 00:00:00.00],[2014-12-01 00:00:00.00],[2015-01-01 00:00:00.00],[2015-02-01 00:00:00.00],[2015-03-01 00:00:00.00],[2015-04-01 00:00:00.00],[2015-05-01 00:00:00.00],[2015-06-01 00:00:00.00],[2015-07-01 00:00:00.00],[2015-08-01 00:00:00.00],[2015-09-01 00:00:00.00],[2015-10-01 00:00:00.00],[2015-11-01 00:00:00.00],[2015-12-01 00:00:00.00],[2016-01-01 00:00:00.00]))
AS PVT;

0 个答案:

没有答案