I want same output shown in Output table. I have TableA and I want to pivote it and want output table as shown in image. Thanks在SQL
樞軸表我有一個表#tableA
+-----+-------------+-------+------------+
| A | Allocations | Seats | EndDate |
+-----+-------------+-------+------------+
| ABC | 450 | 23 | 2017-10-05 |
| ABC | 23 | 765 | 2017-05-01 |
| PQR | 54 | 34 | 2017-07-04 |
| ABC | 234 | 45 | 2017-11-27 |
| PQR | 987 | 76 | 2017-03-05 |
| ABC | 76 | 65 | 2017-02-23 |
| PQR | 89 | 324 | 2017-08-14 |
| ABC | 45 | 34 | 2017-07-13 |
+-----+-------------+-------+------------+
哪些可以創建和填充如下。
CREATE TABLE #TableA
(
A VARCHAR(50),
Allocations INT,
Seats INT,
EndDate DATETIME
);
INSERT INTO #TableA
VALUES ('ABC',450,23,'2017-10-05'),
('ABC',23,765,'2017-05-01'),
('PQR',54,34,'2017-07-04'),
('ABC',234,45,'2017-11-27'),
('PQR',987,76,'2017-03-05'),
('ABC',76,65,'2017-02-23'),
('PQR',89,324,'2017-08-14'),
('ABC',45,34,'2017-07-13');
A
列有ABC
和PQR
唯一值。 日期時間列有多個值。
如何獲得以下輸出?
日期時間來自列A中TableA的所有Datetime值。
Output :-
date | 2017-12-13 | 2017-12-20 | 2017-12-27 | -|-|-|-|-|-|-|-|-|
-------------------------------------------------------------------------------
A | ABC | ABC | ABC |
Allocations | 50 | 50 | 50 |
Seats | 27 | 27 | 27 |
A | PQR | PQR | PQR |
Alloc | 50 | 50 | 50 |
Seats | 12 | 12 | 12 |
單擊該問題以查看圖像。 –
嘿謝謝..我會這樣做 –
期望的輸出如何與示例輸入相關聯?爲什麼每天都有'50/27/50/12'? –