Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将左连接限制为多行中最后更新的行_Php_Mysql_Left Join - Fatal编程技术网

Php 将左连接限制为多行中最后更新的行

Php 将左连接限制为多行中最后更新的行,php,mysql,left-join,Php,Mysql,Left Join,这是我的代码,我正在尝试加入最新的团队数据,而不是所有的数据。我试过只使用限制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_na

这是我的代码,我正在尝试加入最新的团队数据,而不是所有的数据。我试过只使用限制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";

这里有一条路。将
左侧连接(选择团队…等…)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...

$start
$end
的值是什么?它们是字符串吗?这些只是日期值,它们不是字符串。在这种情况下,它们需要用倒逗号括起来,但这对我没有帮助,因为团队表每个团队只存储一行?