[英]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.