将一个单轴旋转成两行 - T-SQL
Unpivot a single into two rows - T-SQL
我正在尝试取消旋转下面的行,但我遇到了麻烦。有什么帮助吗?
输入:
Date Time Country_Championship Game Home_Team Away_Team
----------------------------------------------------------------------------
19/07/2020 18:45 Albania: Superliga Bylis Vs Laci Bylis Laci
输出:
Date Time Country_Championship Game Team
---------------------------------------------------------------
19/07/2020 18:45 Albania: Superliga Bylis Vs Laci Bylis
19/07/2020 18:45 Albania: Superliga Bylis Vs Laci Laci
我尝试过的:
SELECT
u.[Date], u.[Time],
u.[Country_Championship],
u.[Game],
u.[Home_Team], u.[Away_Team],
u.details
FROM
[Soccer_Analytics].[dbo].[Ins_UpcomingGames_Temp] t
UNPIVOT
(details FOR [Date], [Time], [Country_Championship], [Game] IN ([Home_Team], [Away_Team])) u;
在 T-SQL 中,我建议为此使用横向连接:
select x.*
from [Soccer_Analytics].[dbo].[Ins_UpcomingGames_Temp] t
cross apply (values
(date, time, country_championship, game, home_team),
(date, time, country_championship, game, away_team)
) as x(date, time, country_championship, game, team)
我正在尝试取消旋转下面的行,但我遇到了麻烦。有什么帮助吗?
输入:
Date Time Country_Championship Game Home_Team Away_Team
----------------------------------------------------------------------------
19/07/2020 18:45 Albania: Superliga Bylis Vs Laci Bylis Laci
输出:
Date Time Country_Championship Game Team
---------------------------------------------------------------
19/07/2020 18:45 Albania: Superliga Bylis Vs Laci Bylis
19/07/2020 18:45 Albania: Superliga Bylis Vs Laci Laci
我尝试过的:
SELECT
u.[Date], u.[Time],
u.[Country_Championship],
u.[Game],
u.[Home_Team], u.[Away_Team],
u.details
FROM
[Soccer_Analytics].[dbo].[Ins_UpcomingGames_Temp] t
UNPIVOT
(details FOR [Date], [Time], [Country_Championship], [Game] IN ([Home_Team], [Away_Team])) u;
在 T-SQL 中,我建议为此使用横向连接:
select x.*
from [Soccer_Analytics].[dbo].[Ins_UpcomingGames_Temp] t
cross apply (values
(date, time, country_championship, game, home_team),
(date, time, country_championship, game, away_team)
) as x(date, time, country_championship, game, team)