SQL: how to select a single id (“row”) that meets multiple criteria from a single column

后端 未结 9 2373
刺人心
刺人心 2020-11-30 05:38

I have a very narrow table: user_id, ancestry.

The user_id column is self explanatory.

The ancestry column contains the country from where the user\'s ancest

9条回答
  •  执念已碎
    2020-11-30 06:14

    brute force (and only tested on an Oracle system, but I think this is pretty standard):

    select distinct usr_id from users where user_id in (
        select user_id from (
          Select user_id, Count(User_Id) As Cc
          From users 
          GROUP BY user_id
        ) Where Cc =3
      )
      and ancestry in ('England', 'France', 'Germany')
    ;
    

    edit: I like @HuckIt's answer even better.

提交回复
热议问题