4

假设我有一个名为Domain. 如何从该表中找到最受欢迎的电子邮件域。直接我想找到具有最大计数的所有行。

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
4

2 回答 2

2
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)
于 2012-09-22T12:29:44.450 回答
2
SELECT Domain, count(id)
FROM Domain
GROUP BY Domain.Domain
HAVING count(id) = (SELECT count(id) FROM Domain D GROUP BY D.Domain ORDER BY count(id) DESC LIMIT 1)
于 2012-09-22T13:45:28.280 回答