select OrderID,ProdDetailID from A表A :OrderID,ProdDetailID1 61 71 92 52 3如:orderID=1 的列转行select STUFF((SELECT ','+ cast(ProdDetailID as varchar(4)) FROM A where A.OrderID=1 FOR XML PATH('')), 1, 1, '')结果:6,7,9