sql server 根據特定欄位分組後,對當前分組資料其他欄位進行拼接處理。
SELECT 欄位1, [列名] = stuff(( SELECT ',' + [欄位2] FROM aa t WHERE t.欄位1 = aa.欄位1 FOR xml path('')) , 1 , 1 , '') FROM aa GROUP BY 欄位1
SELECT 欄位1, [列名] = stuff(( SELECT ',' + [欄位2] FROM aa t WHERE t.欄位1 = aa.欄位1 FOR xml path('')) , 1 , 1 , '') FROM aa GROUP BY 欄位1