假设我们有一个表,例如:
Number Value GroupValue
1 FOO GR1
22 BAR GR2
100 FOO3 GR1
20 BAR23 GR2
我想根据组值获取这些行的总和值,而且,我想查看它在另一列中分组的行,例如:
SUM values groups
101 FOO,FOO3 GR1
42 BAR,BAR23 GR2
我怎样才能在sql中实现这一点?
试过:
> 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
但这不能正确处理组...