Search code examples
mysqlsqlh2

Average after group by in SQL query


select avg(select count(aid)
           from athlete
           group by codepays)

I get a "more than one row error". How with I go about getting the average of the result from my fist select ?


Solution

  • You need to use a table expression (subquery).

    For example:

    select avg(cnt)
    from (
      select count(aid) as cnt
      from athlete
      group by codepays
    ) x