实质为基于派生表的查询
语句:
select 属性 from 表 group by 属性
having count(属性) =(select max(别名)
from
(select count(属性) as 别名 from orders group by customer_id)表别名)
eg:从orders表中选取订单数目最多的客户
select customer_id,count(order_id) from orders group by customer_id
having count(order_id) =(select max(temp.amount)
from
(select count(order_id) as amount from orders group by customer_id)temp)
结果:
![](https://i-blog.csdnimg.cn/blog_migrate/29f8e8993ab95c5a355cd9ffe835dc86.png)