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