有条款的MySQL未知列

前端之家收集整理的这篇文章主要介绍了有条款的MySQL未知列前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图获得每个团队的所有胜利,但是,sql决定抛出一个错误

正在执行以下查询

SELECT `t`.`teamcode`,COUNT(*) AS `gewonnen`
FROM `Team` `t`
INNER JOIN `Wedstrijd` `w` ON `w`.`teamthuis` = `t`.`teamcode`
GROUP BY `w`.`teamthuis`
HAVING `w`.`scorethuis` > `w`.`scoreuit`

#1054 - Unknown column 'w.scorethuis' in 'having clause'

没有别名:

SELECT `Team`.`teamcode`,COUNT(*) AS `gewonnen`
FROM `Team`
INNER JOIN `Wedstrijd` ON `Wedstrijd`.`teamthuis` = `Team`.`teamcode`
GROUP BY `Wedstrijd`.`teamthuis`
HAVING `Wedstrijd`.`scorethuis` > `Wedstrijd`.`scoreuit`

#1054 - Unknown column 'Wedstrijd.scorethuis' in 'having clause'
最佳答案
没有必要使用HAVING.试试WHERE:

SELECT `t`.`teamcode`,COUNT(*) AS `gewonnen`
FROM `Team` `t`
INNER JOIN `Wedstrijd` `w` ON `w`.`teamthuis` = `t`.`teamcode`
WHERE `w`.`scorethuis` > `w`.`scoreuit`
GROUP BY `w`.`teamthuis`
原文链接:https://www.f2er.com/mysql/433265.html

猜你在找的MySQL相关文章