我试图通过以下查询获得所需的结果,但似乎无法正常工作...
如果我删除最后两个LEFT JOIN,查询将正常工作...另外两个有什么问题吗?我需要使用其他方法才能使其正常工作吗?
谢谢。
SELECT DISTINCT
u.user_name as user_name,
u.total_points as total_points,
u.user_id as user_id,
COUNT(a.id) as user_total_articles_published,
COUNT(r.id) as user_total_replies_published,
COUNT(v.id) as user_total_votes_done
FROM users as u
LEFT JOIN articles as a ON u.user_id=a.user_id
LEFT JOIN replies as r ON u.user_id=r.user_id
LEFT JOIN votes as v ON u.user_id=v.user_id
GROUP BY u.user_id
ORDER BY u.total_points DESC
LIMIT 10
如果我删除最后两个LEFT JOIN,查询将正常工作...另外两个有什么问题吗?我需要使用其他方法才能使其正常工作吗?
谢谢。