我在锦标赛数据库中建立和实施“时间”事件时遇到了麻烦。
我有三个实体:球员,球队,转会,冠军,我想跟踪球员在冠军赛期间的转会(球员可以在冠军期间转移到另一支球队)
championship(id_championship*, name, year*)
player (id_player*, name, number, id_team*)
team (id_team, name)
transfer (id_player*, id_team_from*, id_team_to*, transfer _date)
感谢。
答案 0 :(得分:1)
您可以尝试此查询,例如:
Select T1.id_player, T1.id_team_from as Team, T1.Transfer_date as PeriodFrom,
T2.Transfer_date as PeriodTo
from
(Select id_player,id_team_from, id_team_to, Transfer_date,
row_number() over (partition by id_player order by transfer_date desc) RN1)T1
inner join
(Select id_player,id_team_from, id_team_to, Transfer_date,
row_number() over (partition by id_player order by transfer_date desc) RN2)T2
on T1.RN1=T2.RN2+1
and T1.id_player=T2.id_player
它应该让所有参与其中队伍的球员从PeriodFrom返回到PeriodTo。