现状
date (nvarchar(9))
sku (nvarchar(5))
smith (decimal)
jones (decimal)
jonson (decimal)
nguyen (decimal)
date sku smith jones johnson nguyen
-----------------------------------------------------------
11/4/2007 X2271 2404 9055,33 7055,22 0
11/4/2007 B1112 108,99 0 244,92 1001.01
请求结果:
date sku salesperson sales
------------------------------------------
11/4/2007 X2271 Smith 2404
11/4/2007 X2271 Jones 9055,33
11/4/2007 X2271 Johnson 7055,22
11/4/2007 B1112 Smith 108,99
11/4/2007 B1112 Johnson 244,92
11/4/2007 B1112 Nguyen 1001,01
需要一些帮助来解决这个问题。此任务与BI任务相关。
答案 0 :(得分:2)
您可以使用UNPIVOT
命令来完成此操作。
SELECT
date,
sku,
salesperson,
sales
FROM (
SELECT
date,
sku,
smith,
jones,
johnson,
nguyen
FROM
YourTable
) q
UNPIVOT
(sales FOR salesperson in (smith, jones, johnson, nguyen)) AS YourUnpivot