Select values that meet different conditions on different rows?

前端 未结 6 2118
甜味超标
甜味超标 2020-11-22 07:37

This is a very basic query I can\'t figure out....

Let\'s say I have a two column table like this:

userid  |  roleid
--------|--------
   1    |    1         


        
6条回答
  •  我在风中等你
    2020-11-22 08:30

    Assuming userid, roleid are contained in a unique index (meaning there cannot be 2 records where userid = x and roleid = 1

    select count(*), userid from t
    where roleid in (1,2,3)
    group by userid
    having count(*) = 3
    

提交回复
热议问题