Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有三个看起来像的表:
users: id event_registration: id user_id event_id events: id
用户注册一个事件,该注册记录在 event_registration 中。
有没有一种方法可以计算给定一组用户在单个 MySQL 语句中相互共享的事件计数?我想出了如何为两个用户执行此操作,但我想对其进行重构以支持 X 个用户(仅包括一个用户)。
尝试
select count(event_id) as events from event_registration where user_id in (1,2,3) group by event_id having count(distinct user_id) = 3
您必须根据您3在子句中使用的 shaving的数量来调整子句中的数字。user_idin
3
having
user_id
in