0
我有一個查詢,產生所需的輸出,但不是在正確的佈局。我需要將一些列作爲一個組來旋轉,但不知道如何去做。查詢,樞軸多列
查詢如下:
SELECT Line.DocumentName
,Package.PackageName
,Package.ContainerCount
,Package.PageCount
,m.Name Media
FROM Invoice i
JOIN Section s ON i.InvoiceDate = s.InvoiceDate
JOIN Line l ON s.InvoiceDate = l.InvoiceDate AND s.DocumentTypeID = l.DocumentTypeID
JOIN Package p ON l.InvoiceDate = p.InvoiceDate AND l.DocumentTypeID = p.DocumentTypeID AND l.DocumentDate = p.DocumentDate
JOIN MediaType m ON p.MediaTypeID = m.Id
WHERE i.InvoiceDate = '6/1/2017';
這將返回:
|varchar(100) |char(2) |int |int |varchar(10)|
|--------------------|-----------|--------------|---------|-----------|
|DocumentName |PackageName|ContainerCount|PageCount|Media |
|--------------------|-----------|--------------|---------|-----------|
|Invoices17_05_26.xml|01 | 1758| 2024|A |
|Invoices17_05_26.xml|30 | 382| 1728|Email |
|Invoices17_05_30.xml|01 | 2757| 3336|A |
|Invoices17_05_30.xml|30 | 626| 2101|Email |
|Credits17_05_01.xml |01 | 1346| 1488|A |
|Credits17_05_01.xml |30 | 390| 451|Email |
|Credits17_05_08.xml |01 | 0| 0|C |
|Credits17_05_08.xml |30 | 353| 408|Email |
|Stmts-17_05_01.xml |01 | 14796| 15299|B |
|Stmts-17_05_01.xml |30 | 2888| 3267|Email |
不過,我需要的輸出有這樣的佈局:
|DocumentName |01 ContainerCount|01 PageCount|01 Media|30 ContainerCount|30 PageCount|30 Media|
|--------------------|-----------------|------------|--------|-----------------|------------|--------|
|Invoices17_05_26.xml| 1758| 2024|A | 382| 1728|Email |
|Invoices17_05_30.xml| 2757| 3336|A | 626| 2101|Email |
|Credits17_05_01.xml | 1346| 1488|A | 390| 451|Email |
|Credits17_05_08.xml | 0| 0|C | 353| 408|Email |
|Stmts-17_05_01.xml | 14796| 15299|B | 2888| 3267|Email |
我已經試過變化以下,無果: