我有一张桌子:
TICKER DATE SHAREPRICE
--------------------------------
ABC 1.1.2015 50
XYZ 1.1.2015 100
等
我想进行查询,结果如下:
DATE PRICE(TICKER ABC) PRICE(TICKER XYZ)
--------------------------------------------
1.1.2015 50 100
答案 0 :(得分:1)
在SQL SERVER中使用PIVOT。
DECLARE @test AS TABLE(TICKER VARCHAR(10), DATE DATETIME, SharePrice INT)
INSERT INTO @test
SELECT 'ABC', '1/1/2015', 50 UNION
SELECT 'XYZ', '1/1/2015', 100
SELECT Date, ABC AS [PRICE(TICKER ABC)], XYZ AS [PRICE(TICKER XYZ)] FROM @test
PIVOT(MAX(SharePrice) FOR Ticker IN(ABC, XYZ)) AS A
答案 1 :(得分:0)