我的数据看起来像
Viral Impressions Paid Impressions Organic Impressions
123 5678 34566
我希望它采用这种格式。
Impressions
Viral 123
Paid 5678
Organic 34566
如何使用Pivot unpivot在SSIS中执行此操作
答案 0 :(得分:1)
作为UNPIVOT的替代方案,您可以使用UNION ALL:
Select 'viral' as col, [viral impressions] as impressions
From yourtable
Union all
Select 'paid' as col, [paid impressions] as impressions
From yourtable
Union all
Select 'organic' as col, [organic impressions] as impressions
From yourtable
给出结果:
| COL | IMPRESSIONS |
-------------------------
| viral | 123 |
| paid | 5678 |
| organic | 34566 |
答案 1 :(得分:0)
使用UNPIVOT
表格运算符:
SELECT
value,
Impressions
FROM TableName
UNPIVOT
(
Impressions
FOR value IN([Viral],
[Paids],
[Organic])
) u;
这假设列的名称存储为Viral | Paid | Organic
。如果这些列的名称为Viral Impressions | Paid Impressions | Organic Impressions
那么您可以执行此操作:
WITH CTE
AS
(
SELECT value, Impressions
FROM Table1
UNPIVOT
(
Impressions
FOR value IN([Viral Impressions],
[Paid Impressions],
[Organic Impressions])
) u
)
SELECT
REPLACE(value, ' Impressions', '') Value,
Impressions
FROM CTE;