I think you need something like this:
SELECT mid
FROM your_table
WHERE uid in ('favour','crackhead','charisma')
GROUP BY mid
HAVING COUNT(*)=3
EDIT: based on your second example, this is what you are looking for:
SELECT mid
FROM your_table
WHERE uid in ('vweetah', 'crackhead')
GROUP BY mid
HAVING
COUNT(distinct uid)=
(select count(*)
from (select 'vweetah' union select 'crackhead') s)
or you can just substitute last subquery with the number of elements you are looking for, e.g. HAVING COUNT(distinct uid) = 2
EDIT2: now i understand exactly what you are looking for. This should give you the correct results:
SELECT your_table.mid, s.tot_count, count(distinct uid)
FROM
your_table inner join
(select mid, seq, count(distinct uid) tot_count from your_table group by mid, seq) s
on your_table.mid = s.mid and your_table.seq=s.seq
WHERE your_table.uid in ('crackhead')
GROUP BY your_table.mid
HAVING COUNT(distinct uid)=s.tot_count AND COUNT(distinct uid)=1
where the last count is equal to the number of elements you are looking for. This could be simplified like this:
SELECT your_table.mid
FROM your_table
GROUP BY your_table.mid
HAVING
count(distinct uid)=
count(distinct case when your_table.uid in ('vweetah','crackhead','chuks.obima') then your_table.uid end)
and count(distinct uid)=3
如果如果所有 uid 都在同一组下,则认为该组已关闭seq
,您还必须修改 group by with:group by your_table.mid, your_table.seq
和您的 select withSELECT distinct your_table.mid