我真的很新。目前工作的SQL Server 2012年SQL Server表操作
我有以下結構(記錄完整數據表的子集)的表答:
CREATE TABLE [dbo].[TABLE_A](
[ASSET ID] [float] NULL,
[TASK ID] [float] NULL,
[IN_YEAR ] [float] NULL,
[IN_WEEK] [float] NULL,
[FLAG] [nvarchar](1) NULL
) ON [PRIMARY]
INSERT INTO TABLE_A
([ASSET ID], [TASK ID], [IN_YEAR], [IN_WEEK], [FLAG])
VALUES
(1, 1, 2015, 19, 'N'),
(1, 1, 2015, 20, 'Y'),
(1, 1, 2015, 21, 'N'),
(1, 2, 2015, 19, 'Y'),
(1, 2, 2015, 20, 'N'),
(1, 2, 2015, 21, 'N'),
(2, 1, 2015, 19, 'N'),
(2, 1, 2015, 20, 'N'),
(2, 1, 2015, 21, 'N')
;
在表A中,我們總是有相同的週數/年,資產ID和任務ID的每個唯一組合。
,並想將它翻譯成B表結構:
+----------+---------+--------------+--------------+--------------+
| Asset ID | Task ID | 2015–WEEK 19 | 2015–WEEK 20 | 2015–WEEK 21 |
+----------+---------+--------------+--------------+--------------+
| 1 | 1 | N | Y | N |
| 1 | 2 | Y | N | N |
| 2 | 1 | N | N | N |
+----------+---------+--------------+--------------+--------------+
有什麼想法?
你可能會發現你的答案[這裏](http://stackoverflow.com/questions/13372276/simple-way-to-transpose-columns-and-rows-in-sql)... –