这是我的代码,我试图加入最新的团队数据,而不是每条数据。我试过只使用限制 1 但没有返回任何东西ORDER BY 更新的 DESC LIMIT 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";
1 回答

函数式编程
TA贡献1807条经验 获得超9个赞
这是一种方法。替换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...
- 1 回答
- 0 关注
- 90 浏览
添加回答
举报
0/150
提交
取消