【发布时间】:2019-07-06 09:05:24
【问题描述】:
一直在尝试各种转置方法,包括枢轴,&
聚合/CASE,但似乎没有任何工作正常。
希望转置最后 3 列(5 列矩阵)
到每个唯一 ID 的行中。下图。
这似乎是一个如此简单的问题。真的应该有 一个简单的解决方案。
谁能指出我正确的方向?
Here is the code to generate the temporary table:
-- -- BEGIN: Clean up temp tables: -- -- -- -- -- -- -- -- -- -- -- -
--
-- Remove the temporary table if it exists -- -- -- -- -- -- --
If OBJECT_ID('tempdb..#StrongmanTempTable') is NOT NULL
BEGIN
-- PRINT N'Table exists. Now deleting...';
DROP TABLE #StrongmanTempTable
END
--
-- -- END: Clean up temp tables: -- -- -- -- -- -- -- -- -- -- -- -
CREATE TABLE #StrongmanTempTable
(
EntrantID INT,
Entrant VARCHAR (64),
Event VARCHAR (64),
Judge1Score float,
Judge2Score float,
)
INSERT INTO #StrongmanTempTable
VALUES
(1, 'Bluto', 'Tire Flip', 9.0, 9.9),
(1, 'Bluto', 'Vehicle Pull', 6.3, 9.8),
(2, 'Mighty Mouse', 'Log Throw', 6.1, 7.7),
(2, 'Mighty Mouse', 'Tire Flip', 7.2, 9.0),
(3, 'Popeye', 'Vehicle Pull', 9.0, 8.3),
(2, 'Mighty Mouse', 'Vehicle Pull', 7.4, 7.8),
(3, 'Popeye', 'Log Throw', 8.0, 9.7),
(1, 'Bluto', 'Log Throw', 8.2, 8.3),
(3, 'Popeye', 'Tire Flip', 6.5, 9.2)
-- For testing:
SELECT * FROM #StrongmanTempTable
【问题讨论】: