很抱歉这样一般的问题,但我真的很难找出为什么我收到错误Unknown column 'tbl_downloads.itemid' in 'on clause'
。在tbl_downloads表中绝对有一个名为itemid的列。
SELECT tbl_downloads.itemid,COUNT(tbl_downloads.itemid*temp1.score) AS score2
FROM tbl_downloads,temp1
LEFT JOIN temp2 ON tbl_downloads.itemid=temp2.itemid
WHERE temp2.itemid IS NULL
AND tbl_downloads.memberid=temp1.memberid
GROUP BY tbl_downloads.itemid
ORDER BY score2 DESC
LIMIT 50;
答案 0 :(得分:8)
最好在使用隐式和显式连接语法时保持一致 - 这将是一个改进:
SELECT tbl_downloads.itemid, COUNT(tbl_downloads.itemid*temp1.score) AS score2
FROM tbl_downloads
JOIN temp1 ON tbl_downloads.memberid=temp1.memberid
LEFT JOIN temp2 ON tbl_downloads.itemid=temp2.itemid
WHERE temp2.itemid IS NULL
GROUP BY tbl_downloads.itemid
ORDER BY score2 DESC
LIMIT 50;
答案 1 :(得分:4)
我真的很难找出为什么我收到错误
Unknown column 'tbl_downloads.itemid' in 'on clause'
LEFT JOIN
适用于temp1
和temp2
。如果您按如下方式格式化查询,问题将变得更加清晰:
SELECT ...
FROM tbl_downloads,
(temp1 LEFT JOIN temp2 ON tbl_downloads.itemid=temp2.itemid)
...
因此tbl_downloads
不在ON
子句的范围内。