此代码仅返回具有评级的帖子。如果帖子没有评级,我如何获取所有具有空值的帖子?
select
posts.id,
posts.user_id,
posts.name,
posts.created_at,
ratings.post_id,
ratings.avg,
ratings.count
from
posts
join (
select
post_id,
avg(rating) as avg,
count(rating) as count
from
ratings
group by
ratings.post_id
) ratings
on ratings.post_id = posts.id
Run Code Online (Sandbox Code Playgroud)