Imagine we have a table such as:
Number Value GroupValue
1 FOO GR1
22 BAR GR2
100 FOO3 GR1
20 BAR23 GR2
I want to get the sum values of these rows based on group value,but also ,i want to see which rows it has grouped by in another column such as:
SUM values groups
101 FOO,FOO3 GR1
42 BAR,BAR23 GR2
How can i achieve that in sql?
Tried:
> SELECT SUM(ID) AS SUM ,
STUFF(( SELECT ',' + A
FROM dbo.Table_1 AS T2
WHERE A = T2.A
FOR
XML PATH('')
), 1, 1, '') AS A ,
B
FROM dbo.Table_1 AS T
GROUP BY B ,
A
But this can not handle the groups properly...