【发布时间】:2018-05-11 05:16:15
【问题描述】:
我已使用 Cross apply 将数据从 Wide 转换为 Tall 格式。使用以下问题的答案来实现Using PIVOT to Flip Data from Wide to Tall
我创建了临时列Sector。我想将此列用于与另一个表的左连接。但我在这条线上V.Sector = S.[Sector name] 收到错误V.Sector = S.[Sector name]
SELECT Date,
Country,
Sector,
PE,
PX_BOOK
S.Sector_level
FROM [Economic_Data].[dbo].[Sector_Valuations] V
CROSS APPLY
(
VALUES
('Large Cap Equity',[Large Cap Equity_PE],[Large Cap Equity_book]),
('Mid Cap Equity',[Mid Cap Equity_PE],[Mid Cap Equity_book]),
('Small Cap Equity',[Small Cap Equity_PE],[Small Cap Equity_book]),
('Value Index',[Value Index_PE],[Value Index_book]),
('Growth Index',[Growth Index_PE],[Growth Index_book]),
) x (Sector, PE, PX_BOOK)
Left join [Economic_Data].[dbo].[Sector level] S
on V.Sector = S.[Sector name]
谁能帮我解决这个问题。谢谢!
【问题讨论】:
标签: sql sql-server join cross-apply