ListAGG in SQLSERVER

Starting in SQL Server 2017 the STRING_AGG function is available which simplifies the logic considerably: See SQL Fiddle with Demo In SQL Server you can use FOR XML PATH to get the result: See SQL Fiddle with Demo

Aggregate multiple columns at once

We can use the formula method of aggregate. The variables on the ‘rhs’ of ~ are the grouping variables while the . represents all other variables in the ‘df1’ (from the example, we assume that we need the mean for all the columns except the grouping), specify the dataset and the function (mean). Or we can use summarise_each from dplyr after grouping (group_by) Or using summarise with across (dplyr devel version … Read more