我有这样一张桌子:
+--------+--------+
| userid | events |
+--------+--------+
| 1 | blog |
| 2 | blog |
| 1 | site |
| 1 | move |
| 2 | move |
| 3 | blog |
| 2 | blog |
+--------+--------+
Run Code Online (Sandbox Code Playgroud)
我想显示参与我作为参数传递的所有事件的所有用户.
示例:参与"博客"和"移动"的所有用户
知道用户可以多次参加活动.
谢谢你的帮助
select userid
from your_table
where events in ('blog','move')
group by userid
having count(distinct events) = 2
Run Code Online (Sandbox Code Playgroud)
如果您要检查3个事件,请使用
having count(distinct events) = 3
Run Code Online (Sandbox Code Playgroud)