보고서에 대해이보기를 가져와야합니다. 현재 내가 거의 다이,이SQL에서 데이터 뒤집기
Transaction Type Amount (£) Credit Product 1 (£) Product 2 (£) Product 3 (£) Credit Card 2489.58 829.86 739.02 920.70 Debit Card 2314.93 1157.47 987.34 170.13 Cheques/P Orders 11266.38 3755.46 4068.92 3442.00 Credit Card - Web 1974.21 984.93 474.21 515.07 GRAND TOTAL 18045.10 6727.72 6269.49 5047.90
...
Transaction Type AMOUNT (£) CREDIT Product Type Bank Transfer 653.89 Product type 1 Card 1323.24 Product type 1 Cash 4538.12 Product type 1 Direct Debit 118.80 Product type 1 Bank Transfer 653.89 Product type 2 Card 1323.24 Product type 2 Cash 4538.12 Product type 2 Direct Debit 118.80 Product type 2
내 쿼리에서 변경하려면 어떻게해야합니까?
SELECT PT.description AS [Transaction Type],
Sum (P.original_amount) AS [AMOUNT (£) CREDIT],
PR.[description] AS [Product Type]
FROM [X].[dbo].[payment] P
JOIN [X].[dbo].[table1] PT
ON P.payment_id = PT.payment_type_id
JOIN [X].[dbo].[table2] SO
ON SO.payment_type_id = P.payment_type_id
JOIN [X].[dbo].[table3] OI
ON OI.order_id = SO.site_order_id
JOIN [X].[dbo].[table4] PR
ON PR.product_id = OI.product_id
GROUP BY PT.description,
PR.description
나는 당신이 실제로 찾고있는 것은 피벗이라고 생각 : http://blogs.msdn.com/b/spike/archive/2009/03/03/pivot-tables-in-sql-server-a -simple-sample.aspx –