这是我到目前为止所拥有的,但它显示了太多的结果。它将描述行很好地组合在一起,但它是针对每个结果进行的。我基本上想要它,所以只有 3 行。每个班级一个http://prntscr.com/1la4j2
/* 3. List the part number, part description, and item class for each pair of parts that are in the same item
class */
SELECT
t1.partnum,
STUFF((
SELECT ', ' + t2.description
FROM part t2
WHERE t1.class = t2.class
FOR XML PATH (''))
,1,2,'') AS description, t1.class
FROM part t1