这个mysql查询给了我未知的列错误
SELECT count(vs.no) AS no_of_vocabs, level, owner_no FROM vocab_stats as vs
LEFT JOIN (SELECT no, level FROM mst_words) mw ON mw.no = vs.vocab_no
WHERE owner_no = 6 AND correct > 0 AND vs.no_of_vocabs > 50
group by owner_no, level
我该如何解决这个问题?
答案 0 :(得分:2)
您应该使用HAVING
(请参阅documentation on SELECT)
SELECT COUNT(vs.no), level, owner_no FROM vocab_stats as vs
LEFT JOIN (SELECT no, level FROM mst_words) mw ON mw.no = vs.vocab_no
WHERE owner_no = 6 AND correct > 0
GROUP BY owner_no, level
HAVING COUNT(vs.no) > 50
答案 1 :(得分:0)
我猜测未知列是vs.no_of_vocabs
,因为您定义了no_of_vocabs
,但它不是vs
/ vocab_stats
表的一部分,它只是查询。从vs
移除vs.no_of_vocabs
,应该修复它。
如果这不是问题,我们需要查看错误消息。