比如用户和角色的中间表:

某列同时满足两个条件

想查找同时拥有角色id为1和2的用户id,sql如下:

select
    user_id
from
    user_role
group by
    user_id
having
    sum(case when role_id=1 then 1 else 0 end)>0
and
    sum(case when role_id=2 then 1 else 0 end)>0

 

相关文章:

  • 2022-12-23
  • 2021-09-25
  • 2022-01-24
  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-18
  • 2021-12-12
  • 2021-10-12
  • 2022-01-28
  • 2022-12-23
相关资源
相似解决方案