【发布时间】:2013-03-26 13:03:17
【问题描述】:
当我在这里尝试执行下面的 mysql 查询时,我不会返回 WHERE 子句中给出的所有记录 ID。
我想做什么:
- 按 id (IN) 获取所有结果记录
-
JOIN第二个表(websites_thumbs)通过表1记录结果的website_salt
通过表 1 中记录的盐,以及来自父站点的盐 ($parent_salt)
SUM投票并在记录结果中返回(如果在第二个表中没有找到结果返回0)
ID 119 和 250 在第二个表中有投票结果,其他没有。问题 我得到的是,当我执行查询时,它只返回记录 1,119 和 250,其他 id 存在但没有返回?
查询:
// VxZQ85cByb98wUx0f3 => 来自另一个查询的父盐(页面数据查询)
SELECT
SUM(CASE t.thumb when 1 then 1 else 0 end) as thumbs_up,
SUM(CASE t.thumb when -1 then 1 else 0 end) as thumbs_down,
w.*, t.*
FROM websites as w
LEFT OUTER JOIN websites_thumbs AS t
ON t.similar_website_salt = w.salt AND t.website_salt = 'VxZQ85cByb98wUx0f3'
WHERE w.id IN ('1', '20', '31', '4', '199', '250', '633953')
GROUP BY t.similar_website_salt
第一张桌子
第二张桌子
执行结果
希望有人能帮我解决这个问题!
谢谢
【问题讨论】: