我想统计生成超过 2 张发票的客户数量
mysql> select * from invoices;
+-------+--------+---------------------+
| invId | cus_id | timeinfo |
+-------+--------+---------------------+
| 1 | 36 | 2019-02-21 16:47:10 |
| 2 | 33 | 2019-02-21 16:49:22 |
| 3 | 34 | 2019-02-21 16:51:00 |
| 7 | 34 | 2019-02-21 19:02:46 |
| 5 | 36 | 2019-02-21 16:53:55 |
| 6 | 33 | 2019-02-21 19:02:02 |
| 8 | 33 | 2019-02-22 01:36:26 |
| 9 | 34 | 2019-02-22 16:01:20 |
| 10 | 33 | 2019-03-03 13:02:28 |
| 11 | 35 | 2019-03-05 19:11:53 |
| 12 | 32 | 2019-03-13 22:41:38 |
+-------+--------+---------------------+
11 rows in set (0.00 sec)
最佳答案
尝试如下
这将返回拥有多张发票的客户 ID
select cus_id
from invoices
group by cus_id
having count(*)>2
如果您只需要号码,则使用下面的内容将仅返回客户号码
select count(*) as numberofcustomer
from ( select cus_id
from invoices
group by cus_id
having count(*)>2
) a
关于mysql - 统计生成超过 2 张发票的客户 - mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55148937/