Is it possible to concatenate strings with one or more of other group by function like sum, avg, count etc .
Say I have the following table
Id Name O
Try using this.
Like this:
;WITH cte(id, n, o, v) as (
SELECT Id, Name, Order, Value FROM ....
)
SELECT o, names, SUM(v), COUNT(*)
FROM cte AS outer
CROSS APPLY (
SELECT Name+','
FROM cte AS inner
WHERE outer.o = inner.o
ORDER BY Name FOR XML PATH('')
) n(names)
group by o, names