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

GROUP BY for at kombinere/sammensætte en kolonne

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


  1. Sådan bruger du pgBackRest til at sikkerhedskopiere PostgreSQL og TimescaleDB

  2. Adgang til en anden brugers tabel i en Oracle Stored Procedure

  3. MySQL "NOT IN" forespørgsel 3 tabeller

  4. Udforskning af SQL Server 2014 SELECT INTO Parallelism