我有两个问题:一个给我一个与俱乐部有开放合同的球员名单(没有结束日期)
select ejl_players.id,ejl_players.surname ,ejl_club.short_name
from ejl_players
left join ejl_player_rights r on (r.player_id =ejl_players.id and r.start_date=
(select max(start_date) from ejl_player_rights where player_id=ejl_players.id and end_date is null))
left join ejl_clubs on ejl_club.id=r.club_id
where ejl_club.short_name is not null
其次为我提供了自2010年以来没有参加比赛的球员名单
select s.player_id from ejl_play_stat s
left join ejl_protocols p on p.id=s.protocol_id
group by s.player_id
having max(pdate)<'2010-1-1')
我想得到两个结果中都存在的球员名单,即有开放合同但没有参加2年比赛的球员。 第二个查询返回10 000条记录,当我尝试将它们组合起来像Jonny White推荐时,我的查询没有返回(至少在30分钟内没有)
答案 0 :(得分:0)
这应该这样做:
select ejl_players.id,ejl_players.surname ,ejl_club.short_name
from ejl_players
left join ejl_player_rights r on (r.player_id =ejl_players.id and r.start_date=
(select max(start_date) from ejl_player_rights where player_id=ejl_players.id and end_date is null))
left join ejl_clubs on ejl_club.id=r.club_id
where ejl_club.short_name is not null
and ejl_players.id IN (select s.player_id from ejl_play_stat s
left join ejl_protocols p on p.id=s.protocol_id
group by s.player_id
having max(pdate)<'2010-1-1')