SQL query at least one of something

前端 未结 6 692
鱼传尺愫
鱼传尺愫 2021-02-01 07:33

I have a bunch of Users, each of whom has many Posts. Schema:

Users: id
Posts: user_id, rating

How do I find all Users who have at least one po

6条回答
  •  长情又很酷
    2021-02-01 08:20

    SELECT max(p.rating), u.id 
      from users u 
    INNER JOIN posts p on users.id = p.user_id 
    where p.rating > 10 
    group by u.id;
    

    Additionally, this will tell you what their highest rating is.

提交回复
热议问题