DECLARE @B TABLE(col1 VARCHAR(6),col2 varchar(60),col3 varchar(6),col4 int)
INSERT INTO @B
SELECT '01','25100135301','a',16 UNION ALL
SELECT '01','25100135301','b',12 UNION ALL
SELECT '01','60300100001','a',10
SELECT col1,col2,
STUFF(
(SELECT ', ' + CONVERT(VARCHAR(100),col3) FROM @B T1 WHERE T1.col2 = T2.col2 FOR XML PATH('')),1,1,''
) AS col3,sum(col4) col4
FROM @B T2
GROUP BY col1,col2
------解决方案--------------------
2005 及以后版本可以用with
;with B as(
select .... from tbl where ...
)select .... from b ....