-1

对于这样一个笼统的问题,我很抱歉,但我真的很难找出我收到错误的原因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;
4

2 回答 2

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;
于 2013-04-10T13:21:53.363 回答
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条款的范围内。

于 2013-04-10T13:18:56.257 回答