这是我对好奇者的疑问。只有第一行和最后一行应该涉及这个问题:
SELECT s.parent_id AS id, COUNT(s.parent_id) as count
FROM items i
LEFT OUTER JOIN (SELECT item_id, user_id, MAX(created_at) as created_at
FROM item_views iv
WHERE iv.user_id = ?
GROUP BY item_id) AS v ON i.id = v.item_id
LEFT OUTER JOIN categories c ON c.id = i.category_id
INNER JOIN (SELECT node.id AS node_id, parent.title AS parent_title, parent.id AS parent_id
FROM categories AS node, categories AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt) s ON s.node_id=i.category_id
WHERE (i.updated_at > v.created_at OR v.created_at IS NULL)
AND i.updated_at > ?
GROUP BY s.parent_id;
当我用
find_by_sql
count
列似乎是字符串
"1"
to_i