[SQL Server] Exemple d'utilisation de la fonction STRING_AGG et WTHIN GROUP
Declare @ListeCommande Table(NumeroClient int, NumCommande int)
Insert @ListeCommande(NumeroClient, NumCommande) Values
(1, 42),
(2, 25),
(1, 86),
(3, 215),
(1, 304),
(2, 28);
Select NumeroClient, String_Agg(NumCommande, ', ') As Orders
From @ListeCommande
Group By NumeroClient
Order By NumeroClient;
Select NumeroClient, String_Agg(NumCommande, ', ') Within Group(Order By NumCommande asc) As Orders
From @ListeCommande
Group By NumeroClient
Order By NumeroClient;
Select NumeroClient, String_Agg(NumCommande, ', ') Within Group(Order By NumCommande desc) As Orders
From @ListeCommande
Group By NumeroClient
Order By NumeroClient;