0
列我有兩個表:現在的SQL Server 2008:轉換行到
CREATE TABLE #A (id int, cond_id int)
INSERT INTO #A (id, cond_id)
VALUES (101,20),
(101,22),
(101,24),
(102,23),
(102,22)
,每個ID可以有4個cond_ids最大。我想填充表#B,以便有一個id,並且根據cond_id升序將所有cond_ids填充到一行中作爲一行。 類似於id 102,cond_id 22進入cond_id並且23進入cond_id2。
create table #B (id int, cond_id1 int, cond_id2 int, cond_id3 int, cond_id4 int)
期望的結果:
表#B
id cond_id1 cond_id2 cond_id3 cond_id4
101 20 22 24 null
102 22 23 null null
提前感謝!
您是否嘗試過谷歌有關T-SQL –
甚至看相關欄這個職位的合適的PIVOT子句。 –
我找不到任何東西。 – user3381370