我正在计算撰写帖子的用户的平均分数。但是,现在我想平均他们评论的帖子的分数。我的查询(不包括评论)如下所示:
SELECT u.user_fullname, ROUND(AVG(p.total_points),2) avgPoints
FROM cl_user_identities u
JOIN cl_posts p ON p.user_identity_id = u.user_identity_id
GROUP BY u.user_identity_id
如何添加用户也评论过的帖子?
这是我的表架构:
cl_posts
- post_id
- user_identity_id
- post_title
- total_points
cl_comments
- comment_id
- post_id
- user_identity_id
- comment_text
cl_user_identities
- user_identity_id
- user_fullname
任何帮助都会很棒!