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

Sql seleziona raggruppa per e string concat

questo funzionerà con sql-server 2008

SELECT p1.ID,
       ( SELECT NAME + ' and ' 
           FROM YourTable  p2
          WHERE p2.ID = p1.ID
          ORDER BY NAME
            FOR XML PATH('') ) AS Name,
        sum(Amount)
      FROM YourTable p1
      GROUP BY ID ;