How to select multiple rows of data in a single row in SQL Server

Описание к видео How to select multiple rows of data in a single row in SQL Server

How to select multiple rows of data in a single row in SQL Server
Convert Multiple rows into a single row with commas separated

INPUT QUERY
-----------------------------------
SELECT
c.CategoryName
, sc.SubCategoryName
FROM SubCategory sc
INNER JOIN Category c
ON sc.CategoryID = c.CategoryID

OUTPUT QUERY
------------------------------------
SELECT
c.CategoryName
,STRING_AGG(sc.SubCategoryName, ',') AS SubCategories
FROM SubCategory sc
INNER JOIN Category c
ON sc.CategoryID = c.CategoryID
GROUP BY c.CategoryName


#sqlserver2017
#sqlserver2019
#sqlserver2022

Комментарии

Информация по комментариям в разработке