我有一个包含两个表forum_posts
和forum_replies
的论坛。我需要获得最活跃的用户。这是我最近尝试过的事情
SELECT forum_reply.added_by, forum_posts.added_by FROM forum_reply LEFT JOIN forum_posts ON forum_posts.added_by = forum_reply.added_by
UNION
SELECT forum_posts.added_by, forum_reply.added_by FROM forum_posts RIGHT JOIN forum_reply ON forum_reply.added_by = forum_posts.added_by
WHERE forum_reply.date_added < '".$now."' AND forum_reply.date_added > '".$past24h."' AND forum_posts.date_added < '".$now."' AND forum_posts.date_added > '".$past24h."'
GROUP BY forum_reply.added_by, forum_posts.added_by ORDER BY COUNT(*) DESC LIMIT 5");
问题是这个查询只给了我一个结果而不是5.结果肯定不是真的,因为这个查询给我的用户在过去24小时内没有发布任何内容。