mysql 时间年
mysql temporal year
我在锦标赛数据库中建模和实施 "temporal" 事件时遇到问题。
我有三个实体:球员、球队、转会、冠军,我想跟踪球员在冠军期间的转会(球员可以在冠军期间转会到另一支球队)
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)
谢谢。
您可以试试这个查询,例如:
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
它应该 return 所有球员和他们参加过的球队,从 PeriodFrom 到 PeriodTo。
我在锦标赛数据库中建模和实施 "temporal" 事件时遇到问题。
我有三个实体:球员、球队、转会、冠军,我想跟踪球员在冠军期间的转会(球员可以在冠军期间转会到另一支球队)
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)
谢谢。
您可以试试这个查询,例如:
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
它应该 return 所有球员和他们参加过的球队,从 PeriodFrom 到 PeriodTo。