我有一个充满订单的数据库,其中包含一个 id
和一个 customerName
。我想做的是,找出有多少不同的订单大小。如果客户下了多个订单,将包含多个包含相同 customerName
我想要一个看起来有点像这样的输出:
+------------+----------+
| size | quantity |
+------------+----------+
| 1 | 321 |
| 2 | 148 |
| 3 | 98 |
| 4 | 63 |
| 5 | 22 |
| 6 | 3 |
+------------+----------+
编辑 1:
+------------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------------+-----------------+------+-----+---------+----------------+
| id | int(6) unsigned | NO | PRI | NULL | auto_increment |
| signupDate | date | YES | | NULL | |
| customerName | varchar(128) | YES | | NULL | |
+------------------+-----------------+------+-----+---------+----------------+
最佳答案
select
size,count(1)
from
(
select customerName,count(1) as size from table group by customerName
) tmp group by size
如果这是你想要的?
关于MySQL Couting 重复项的重复项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44490275/