メールアドレスとユーザーの都市を保存する「データ」という名前のテーブルがあり、最も人気のあるメールドメインを見つけたいと考えています。次のクエリを使用して、最大値を持つ行を見つけます。私のテーブルの例:
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が存在しません」というエラーを出しています。助けて。