Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

GROUP BY per combinare/concatenare una colonna

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
  • Demo SQLFiddle