[英]How do I exclude infrequent usernames from mysql query?
我有这个代码
SELECT usernames FROM table1
我想从table1
选择每个username
,但是我想排除在table2
中出现少于5次的usernames
。
因此,我要这样做:从table1中选择所有用户名,但不包括出现在table2中少于5行的用户名。
我怎样才能做到这一点?
select table1.username
from table1
inner join (select username,
count(*) as count from table2
group by username
having count > 5) as tmp
on table1.username = tmp.username
select username from table1 where username in
(
select username from (
select username ,
count( * )
from table2
group by username
having count( * ) > 5
) as x
);
在mysql 5.6上测试: 模式和代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.