我有两个表,表A:
列1
A
B
C
表B:
列1 列2
A 1
A 2
A 3
B 3
B 6
我想得到结果
A 1、2、3
B 3、6
C
有什么好办法呢?我现在弄了个函数取表B的值.但速度太慢了..
------解决方案--------------------
- SQL code
select 列1,stuff((select ','+列2 from 表B where 列1=a.列1 for xml path('')),1,1,'')from 表A a
------解决方案--------------------
------解决方案--------------------
- SQL code
2000 也就 group by 然后 加个 函数
------解决方案--------------------
2K 也就那么点方法。。
------解决方案--------------------
------解决方案--------------------
create function fun_test(@a int)
returns varchar(100)
as
begin
delcare @temp varchar(100)
set @temp = ''
select @temp = @temp + col1 from tb where [email protected]
return @temp
end