-1

我在我的冠军数据库中建模和实施“时间”事件时遇到了麻烦。

我有三个实体:球员,球队,转会,冠军,我想在冠军期间跟踪球员的转会(球员可以在冠军期间转移到另一支球队)

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)

谢谢。

4

1 回答 1

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 的所有球员以及他们参加过的球队。

于 2016-01-27T17:50:23.687 回答