部分原始表数据
需求: 按routineId进行group分组
初步想法(错误):
select r *
from autowork.dbo.PartOnRoutine
where routineId='1050' or routineId='1060'
group by routineId;
难点:一个routineId对应多个part,需先将part合并,再分组
解决:xml
select routineId,(select [partnr]+',' from autowork.dbo.PartOnRoutine
for XML PATH('')) AS PARTNRS
from autowork.dbo.PartOnRoutine
where routineId='1050' or routineId='1060'
group by routineId;
结果: