我有一个名为“数据”的表,其中存储了用户的电子邮件地址和城市,我想找到最受欢迎的电子邮件域。我使用以下查询来查找具有最大值的行。我的桌子的例子:
Email Name City
dsmks@gmail.com John California
sak@gmail.com Leo sydney
dsnk@gmail.com Ross NY
askd@yahoo.com Ronny Canberra
ajs@yahoo.com Monty London
kasl@yahoo.com Jim washington
uy@hotmail.com Finn Las vegas
我已经使用这个查询计算了答案
select x.city, x.No_of_People from (select e.city, count(e.city) as No_of_People from data e group by e.city) x
where x.No_of_People = (select max(x2.No_of_People) from (select e2.city, count(e2.city) as No_of_People from data e2 group by e2.city) x2)
但我不想使用限制,因为它不会返回多行。所以我使用这个答案使用了以下查询
select
x.substring_index (email,'@',-1),
x.No_of_Users
from
(select
e.substring_index (email,'@',-1),
count(e.substring_index (email,'@',-1)) as No_of_Users
from
data e
group by
e.substring_index (email,'@',-1)) x
where
x.No_of_Users =
(select
max(x2.No_of_Users)
from
(select
e2.substring_index (email,'@',-1),
count(e2.substring_index (email,'@',-1)) as No_of_Users
from
data e2
group by
e2.substring_index (email,'@',-1)) x2)
我正在使用的查询给出了这个错误“FUNCTION e2.substring_index 不存在”。帮我。