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

后端 未结 9 2363
刺人心
刺人心 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:09

    like the answer above but I have a duplicate record so I have to create a subquery with distinct

    Select user_id
    (
       select distinct userid
       from yourtable
       where user_id = @userid
    
    ) t1
    where 
    ancestry in ('England', 'France', 'Germany')
    group by user_id
    having count(user_id) = 3
    

    this is what I used because I have multiple record(download logs) and this checks that all the required files have been downloaded

提交回复
热议问题