我拼接出来的结果是
A 1,2,3
B 1,2
但是我现在想得到的结果是
A 3,2,1
B 2,1
这应该怎么排序
------解决思路----------------------
在FROM TB那里排序
改成FROM (SELECT * FROM TB ORDER BY XXX) AS T
------解决思路----------------------
create table pd(col1 varchar(5),col2 int)
insert into pd
select 'A',3 union all
select 'A',2 union all
select 'A',1 union all
select 'B',2 union all
select 'B',1
select a.col1,
stuff((select ','+rtrim(b.col2)
from pd b
where b.col1=a.col1
order by b.col2
for xml path('')),1,1,'') 'col2'
from pd a
group by a.col1
/*
col1 col2
----- ----------------------------
A 1,2,3
B 1,2
(2 row(s) affected)
*/