请看下面的查询。

SELECT sub_words.idwords, words_inc.idArticle
(
    SELECT sub0.idwords, SUBSTRING_INDEX(GROUP_CONCAT(sub1.idwords), ',', 10) AS excl_words,        COUNT(sub1.idwords) AS older_words_cnt
    FROM words_learned sub0
    LEFT OUTER JOIN words_learned sub1
    ON sub0.userId = sub1.userId
    AND sub0.order < sub1.order
    WHERE sub0.userId = 1
    GROUP BY sub0.idwords
) sub_words
INNER JOIN words words_inc
ON sub_words.idwords = words_inc.idwords
LEFT OUTER JOIN words words_exc
ON words_inc.idArticle = words_exc.idArticle
AND FIND_IN_SET(words_exc.idwords, sub_words.excl_words)
WHERE words_exc.idwords IS NULL
ORDER BY older_words_cnt
LIMIT 100


这给出了错误


  #1064-您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第3行的'SELECT sub0.idwords,SUBSTRING_INDEX(GROUP_CONCAT(sub1.idwords),',',10)AS exc'附近使用


我单独检查了子查询,并且子查询中没有错误!这里发生了什么?

最佳答案

您错过了from关键字

SELECT sub_words.idwords, words_inc.idArticle
FROM
( ...

10-05 19:34