我需要提取所有匹配的国家/地区,表格结构为:
TABLE NAME | FIELDS
country | id, name
round | id, season_id
season | id, competition_id
competition | id, country_id
match | id, round_id, date
单个match
记录具有以下组成:
id: 60856
round_id: 65
date: 2018-06-02 00:00:00
你可以看到round_id
match
有争议的地方。
在round
表上有以下设计:
id: 65
season_id: 280
season
代表round
的容器,因此season
记录具有以下结构:
id: 161
competition_id: 48
且season
的{{1}}包含所有competition
。 rounds
记录包含competition
:
country
最后是id: 48
coutry_id: 2
:
country
如何提取所有今天比赛的国家?
这就是我的尝试:
id: 2
name: albania
这将返回:
SQLSTATE [42S22]:未找到列:1054'on clause'中的未知列'round.id'
更新:
$app->get('/country/get_countries/{date}', function (Request $request, Response $response, array $args)
{
$sql = $this->db->query("SELECT * FROM country
LEFT JOIN `match` ON round_id = round.id
LEFT JOIN round ON season_id = season.id
LEFT JOIN season ON competition_id = competition.id
WHERE match.datetime = " . $args["date"] . "");
$sql->execute();
$countries = $sql->fetchAll();
return $response->withJson($countries);
});
答案 0 :(得分:0)
SELECT * FROM country
LEFT JOIN competition ON country.id = competition.country_id
LEFT JOIN season ON season.competition_id= competition.id
LEFT JOIN round ON round.season_id= season.id
LEFT JOIN match ON match.round_id= round.id
WHERE match.datetime = " . $args["date"] . ""