如何查找以下查询的数据
原始来源问题 89
表结构: 产品(制造商、型号、类型)
任务:
找出产品表中型号数量最多的制造商以及型号数量最少的制造商。输出:制造商,型号数量
有问题的提示是GROUP BY
,HAVING
和IN
我尝试了各种方法来找到这个基本上我想出的是我需要使用Max(COUNT(model))
结果应该是
maker qty
A 7 --max
C 1 --min
我想出的一个解决方案是
select maker, count(ps.model) as Count from product as ps
group by ps.maker
having count(ps.model) in
(
select max(cnt) from (select count(model) as cnt from product group by maker)t
union
select min(cnt) from (select count(model) as cnt from product group by maker)t
)
有没有其他办法。