本文介绍了为什么这个 SQL 查询失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下 SQL:

SELECT mov
FROM movie
WHERE mov IN
    (
        SELECT mov
        FROM movie_star
        GROUP BY(mov)
        HAVING count(star) > 6
    )
INNER JOIN movie_star
ON movie_star.mov = movie.mov;

执行此查询时出现以下错误:

I am getting the following error when this query is executed:

.ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册在movie_star.mov 上使用'inner join movie_star 附近的语法=第 3 行的 movie.mov'

推荐答案

JOIN 必须放在 WHERE 子句之前.

The JOIN has to go before the WHERE clause.

SELECT movie.mov
FROM movie
INNER JOIN movie_star ON movie_star.mov = movie.mov
WHERE mov IN (SELECT mov FROM movie_star GROUP BY mov HAVING COUNT(star) > 6);

这篇关于为什么这个 SQL 查询失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 22:27