Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Sql select group by e string concat


isso funcionará com o 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 ;