Mysql - 排除 where count > value 但显示所有行

Mysql - Exclude where count > value but showing all rows

我有一个叫 customer_numbers 的 table,像这样:

ID   customer      number

1    1             10001
2    2             10002
3    2             10003
4    3             10004
5    3             10005
6    3             10006
7    3             10007

我想要一个产生以下结果的查询。 IE。仅排除那些只有一个号码的客户。

ID   customer      number

2    2             10002
3    2             10003
4    3             10004
5    3             10005
6    3             10006
7    3             10007

我试过这样的查询:

SELECT ID,customer,number from customer_numbers GROUP BY number HAVING count(*) > 1

添加 GROUP BY 子句列出所有数字,但 count(*) 始终为 1。没有该子句意味着没有列出所有数字,只有一个结果。

正确的查询是什么?

您只需要按 customer

分组
select * from customer_numbers
where customer in(SELECT customer from customer_numbers GROUP BY customer HAVING count(*)>1)