📄 连接重复字段(a;b;c).txt
字号:
题目:
数据库记录:
1 A
1 B
1 C
写个sql语句要得到如下记录。
1 A;B;C
答案:
create table 面试1
(id int not null,
jilu char(1))
insert into 面试1 select 1,'A'
union all select 1,'B'
union all select 1,'C'
select * from 面试1
declare @temp table(a int identity(1,1), id int,jilu char(1))
insert into @temp(id,jilu)
select id,jilu from 面试1
declare @b int,@jilu varchar(50)
select @b=(select min(a) from @temp)
set @jilu=''
while @b<=(select max(a) from @temp where id=1)
begin
set @jilu=@jilu+(select jilu from @temp where a=@b)+';'
set @b=(select min(a) from @temp where a>@b)
end
print @jilu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -