部分原始表數據
需求: 按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;
結果: