Im trying to get a maximum value after im preforming a groupby clause.
select count(*) as count, store_id from sakila.customer
group by store_id
my output for this code is:
count | store_id |
---|---|
326 | 1 |
273 | 2 |
how can i get a max value from the count column? i tried several things and nothing seems to work.
CodePudding user response:
Just order your results and limit them to 1:
select count(*) as count, store_id from sakila.customer
group by store_id
order by count desc
limit 1
CodePudding user response:
select again with counting result as a subquery
select max(count)
from
select count(*) as count, store_id from sakila.customer
group by store_id
) counts