选择多个最大行 [英] Selecting multiple maximum rows
本文介绍了选择多个最大行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个名为Domain
的MySQL表.如何从此表中找到最受欢迎的电子邮件域.我直接想找到具有最大计数的所有行.
Suppose I have a MySQL table named Domain
. How can I find the most popular email domain from this table. Directly I want to find all rows with the maximum count.
Domain
gmail.com
gmail.com
gmail.com
yahoo.com
yahoo.com
yahoo.com
rediffmail.com
rediffmail.com
mail.com
我想要的输出:
Domain No_of_users
gmail.com 3
yahoo.com 3
推荐答案
select
x.Domain,
x.No_of_users
from
(select
d.Domain,
count(d.Domain) as No_of_users
from
Domain d
group by
d.Domain) x
where
x.No_of_users =
(select
max(x2.No_of_users)
from
(select
d2.Domain,
count(d2.Domain) as No_of_users
from
Domain d2
group by
d2.Domain) x2)
这篇关于选择多个最大行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文