简体   繁体   中英

Using aggregate function max in SQL

I have the following query

select 
    sub.W
from 
    (select 
        W, count(W) as N
     from L
     group by W) sub
where 
     sub.N >= max(sub.N)

and I get this error:

Error code 1111, SQL state HY000: Invalid use of group function
Line 1, column 1

What is wrong?

Have you tried this:

select sub.W
from 
(
       select W, count(W) as N
       from L
       group by W
) sub
where n >= (select max(N)
            from
            (
              select count(W) as N
              from L
              group by W
            ) x)

See SQL Fiddle with Demo

Try:

select sub.W    
from 
(
       select W, count(W) as N
       from L
       group by W
) sub    
where sub.N >= (select max(N)
                from (
                       select W, count(W) as N
                       from L
                       group by W
                      ) sub2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM