⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 合并相同id的字符串.sql

📁 SQL语言常用的一些命令各代码
💻 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 + -