LIMIT LEFT联接到多行中最后一个更新的行



这是我的代码,我试图留下最新的团队数据,而不是每一条数据。我试过只使用限制1,但没有返回任何

按更新的下降限制1 排序

不起作用

有什么想法吗?

$sql = "SELECT 
events.id, events.time,events.status, events.home_team,events.away_team,events.league,
ht.id as home_id,ht.name as home_name,at.name as away_name,
statistics.home_goals,statistics.away_goals,statistics.time as game_time,
leagues.id as league_id,leagues.name as league_name,leagues.type as league_type,
country.name as country_name,country.logo, 
hts.home_scored, ats.away_scored, 
hts.home_conceeded,ats.away_conceeded,
hts.home_win,ats.away_win,
hts.home_15,ats.away_15,
hts.home_25,ats.away_25,
hts.home_btts, ats.away_btts, 
hts.home_fts, ats.away_fts, 
hts.home_cs, ats.away_cs, 
hts.home_corners_for, ats.away_corners_for, 
hts.home_corners_against, ats.away_corners_against, 
hts.home_cards, ats.away_cards
FROM events 
LEFT JOIN   teams ht
ON ht.id = events.home_team
LEFT JOIN   teams at
ON at.id = events.away_team
LEFT JOIN leagues
ON leagues.id = events.league
LEFT JOIN country 
ON country.id=leagues.country
LEFT JOIN ( SELECT team,home_scored,home_conceeded,home_win,home_15,home_25,home_btts,home_fts,home_cs,home_corners_for,home_corners_against,home_cards  FROM team_quick_stats ORDER BY updated DESC)  hts 
ON ht.id=hts.team
LEFT JOIN ( SELECT team,away_scored,away_conceeded,away_win,away_15,away_25,away_btts,away_fts,away_cs,away_corners_for,away_corners_against,away_cards  FROM team_quick_stats ORDER BY updated DESC)  ats
ON at.id=ats.team
LEFT JOIN   statistics 
ON statistics.event_id=events.id
WHERE (events.time BETWEEN $start AND $end) ORDER BY country.list_order, leagues.country ASC , leagues.id ASC, events.time ASC, home_name ASC";

这里有一种方法。将LEFT JOIN (SELECT team... etc....) ats替换为。。。

LEFT
JOIN 
( SELECT x.team
, x.etc... 
FROM team_quick_stats x
JOIN 
( SELECT team
, MAX(updated) updated 
FROM team_quick_stats 
GROUP  
BY team
) y
ON y.team = x.team
AND y.updated = x.updated
) ats...