Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

GROUP BY zum Kombinieren/Verknüpfen einer Spalte

SELECT
     [User], Activity,
     STUFF(
         (SELECT DISTINCT ',' + PageURL
          FROM TableName
          WHERE [User] = a.[User] AND Activity = a.Activity
          FOR XML PATH (''))
          , 1, 1, '')  AS URLList
FROM TableName AS a
GROUP BY [User], Activity
  • SQLFiddle-Demo