?? 合并相同id的字符串.sql
字號:
ID COTENT--------------------1 , "aaa"1 , "bbb"1 , "ccc"2 , "aa "2 , "bb" 如何寫sql語句讓相同的id的content合并 就是結果變成ID Cotent-------------------------1 ,"aaabbbccc"2 ,"aabb" declare @a table(id int ,cotent varchar(10))insert into @a select 1,'"aaa"'union all select 1,'"bbb"'union all select 1,'"ccc"'union all select 2,'"aa"'union all select 2,'"bb"'declare @b table (autoid int identity(1,1),id int,cotent varchar(10))insert into @b select * from @adeclare @aa int,@bb int,@cc varchar(20)select @aa=(select min(id) from @b)select @bb=1while @aa<=(select max(id) from @b) begin select @cc=(select replace(cotent,'"','') from @b where id=@aa and autoid=@bb) declare @c table(autoid int identity(1,1),id int,cotent varchar(20)) while @bb<=(select max(autoid) from @b where id=@aa) begin insert into @c select @aa,@cc select @bb=@bb+1 select @cc=@cc+(select replace(cotent,'"','') from @b where id=@aa and autoid=@bb) end select @aa=(select min(id) from @b where id>@aa) endselect id,'"'+cotent+'"'as Cotent from @c where autoid in (select autoid from (select id,max(autoid)as autoid from @c group by id)a)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -