Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

GROUP BY pour combiner/concaténer une colonne

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
  • Démo SQLFiddle