我已經發現了這個有趣的線程刪除重複和排序結果模擬GROUP_CONCAT
Simulating group_concat MySQL function in Microsoft SQL Server 2005?
use test
go
create table methods (
id int identity,
id_exam int,
method int
)
go
insert into methods (id_exam,method) values (1,5)
insert into methods (id_exam,method) values (1,2)
insert into methods (id_exam,method) values (1,5)
insert into methods (id_exam,method) values (2,1)
insert into methods (id_exam,method) values (3,5)
insert into methods (id_exam,method) values (3,2)
insert into methods (id_exam,method) values (3,2)
insert into methods (id_exam,method) values (4,5)
insert into methods (id_exam,method) values (4,3)
select
id_exam,
method = replace ((select method AS [data()]
from methods
where id_exam = a.id_exam
order by id_exam for xml path('')), ' ', ',')
from methods a
where id_exam is not null
group by id_exam
,讓我
1 5,2,5
2 1
3 5,2,2
4 5,3
但是我想從每個刪除重複考試和排序連接結果以獲得
1 2,5
2 1
3 2,5
4 3,5
謝謝。
非常感謝你。它效果很好。 :) –