我想借助下表
制作摘要报告表1:Account
+----+------+---------------+
| Emp| T Amt| Bill Id |
+----+------+---------------+
| 12| 100 | 101 |
| 11| 200 | 102 |
| 12| 50 | 103 |
+----+------+---------------+
预期输出: -
+----+------+---------------+
| Emp| T Amt| Bill Id |
+----+------+---------------+
| 12| 150 | 101,103 |
| 11| 200 | 102 |
+----+------+---------------+
答案 0 :(得分:0)
select
Emp,
sum([T Amt]),
stuff((select ','+ [Bill Id] from Account a where a.Emp = b.Emp for xml path('')),1,1, '') bill_ids
from Account b
group by Emp,bill_ids
order by Emp desc;