您好,他的查询给了我以下错误:
“on 子句”中存在未知列“m.home_team_id”
SELECT DISTINCT (
`m`.`match_id`),
`m`.`competition_id`,
`m`.`date`,
`h`.`team_name` AS "homeTeam", `h`.`team_id` AS "homeTeamID",
`a`.`team_name` AS "awayTeam", `a`.`team_id` AS "awayTeamID",
`o`.`for`, `o`.`against`
FROM `single` bs, `matches` m, `teams` t, `outcomes` o
JOIN `teams` `h` ON `m`.`home_team_id`=`h`.`team_id`
JOIN `teams` `a` ON `m`.`away_team_id`=`a`.`team_id`
WHERE `bs`.`match_id`=`m`.`match_id`
AND `m`.`score_id`=`o`.`outcome_id`
AND `actual_return` IS NOT NULL`enter code here`
m
是名为 matches 的表的别名,该表具有列 home_team_id
和 away_team_id
所以我不明白为什么该列不能'找不到吗?
艾伦。
最佳答案
SELECT
DISTINCT (`m`.`match_id`),
`m`.`competition_id`,
`m`.`date`,
`h`.`team_name` AS "homeTeam",
`h`.`team_id` AS "homeTeamID",
`a`.`team_name` AS "awayTeam",
`a`.`team_id` AS "awayTeamID",
`o`.`for`,
`o`.`against`
FROM `single` bs
join `matches` m ON bs.match_id = m.match_id
join `outcomes` o m.score_id = o.outcome_id
join `teams` t --<--- I don't know what the join is for `teams` here
--- you probably don't need this in the query at all
JOIN `teams` `h` ON `m`.`home_team_id`=`h`.`team_id`
JOIN `teams` `a` ON `m`.`away_team_id`=`a`.`team_id`
WHERE `actual_return` IS NOT NULL
关于MySQL 找不到列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18617625/