逐行选择所有重复值

时间:2017-07-07 16:15:03

标签: sql sql-server database

我有桌子

Building    Stairs
A           Two
B.          Three
C.          Two

我需要输出

A,C.     Two
B.       Three

1 个答案:

答案 0 :(得分:0)

您可以这样做:

SELECT DISTINCT  STUFF((    SELECT ', ' + b.Building
            FROM #table b
            WHERE b.Stairs = a.Stairs               
            FOR XML PATH('') ), 1, 1, '' ) AS Building,
    Stairs
FROM #table a