1
我設法掛我的數據庫服務器做一個查詢:的MySQL/Drupal的:條件JOIN ON語句
SELECT d.name, COUNT(DISTINCT stats_log.id) AS hits, COUNT(DISTINCT stats_log.ip) AS views
FROM stats_log
LEFT JOIN node ON node.nid = stats_log.nid
LEFT JOIN taxonomy_term_data d ON d.tid IN (node.category_tid, node.category_tid2)
GROUP BY d.tid
ORDER BY hits
但是這工作得很好:
SELECT d.name, COUNT(DISTINCT stats_log.id) AS hits, COUNT(DISTINCT stats_log.ip) AS views
FROM stats_log
LEFT JOIN node ON node.nid = stats_log.nid
LEFT JOIN taxonomy_term_data d ON node.category_tid = d.tid
GROUP BY d.tid
ORDER BY hits
所以我的問題是...上午我只是沒有注意到我的查詢中有一些錯誤,或者ON有一些我不知道的限制或有趣的行爲?
node.category_tid2
值大多是NULLd.tid
是主鍵
和最新的區別是什麼?使用兩者的結果相同 – dimention 2015-03-28 16:13:52