可能重复:
How to write a SQL query to present values horizontally
这是我的疑问:
SELECT
ROW_NUMBER() OVER
(
ORDER BY tblProductPackingHdr.bmr_ID
)AS SLNo
,tblProductPackingHdr.bmr_ID
,tblProductPackDetails.pack+' '+MAX(tblUnit.unit_Type)+' * '+CAST(SUM(tblProductPackingFinishedHdr.qty-tblProductPackingFinishedHdr.loss_Qty)AS VARCHAR) AS Pack
FROM
tblProductPackingHdr
INNER JOIN tblProductPackingFinishedHdr ON tblProductPackingHdr.product_Packing_ID=tblProductPackingFinishedHdr.product_Packing_ID
INNER JOIN tblProductPackDetails ON tblProductPackDetails.pack_detl_ID=tblProductPackingFinishedHdr.pack_detl_ID
INNER JOIN tblUnit ON tblUnit.unit_ID=tblProductPackDetails.unit_ID
GROUP BY
tblProductPackingHdr.bmr_ID
,tblProductPackDetails.pack
我得到了这样的输出
SLNo bmr_ID Pack
1 1 450 Ml * 100
2 2 1 Ltr * 12
3 2 350 Ml * 8
4 2 450 Ml * 19
5 27 450 Ml * 44
6 27 670 Ml * 1040
我想像这样显示
SLNO bmr_ID Pack
----------------------
1 1 450 Ml*100
2 2 1 Ltr*12,350 Ml*8,450ml*19
3 27 450 ml*44,670 ml*1040
请帮助