Obtain an id using the count () and max () functions

1

I do not know what title to put to ask this question so all help to get this question resolved is welcome.

Given the following tables:

The result I want to get is the depto_no of the department with the most employees, that is:

I started doing:

SELECT depto_no,count(*) FROM empleado GROUP BY depto_no;

Which gets the following and maybe serves as a subquery to get to the result I want:

But I do not know how to proceed.

    
asked by Serux 11.06.2018 в 21:18
source

1 answer

1

You can do it like this:

SELECT depto_no,count(*) AS cnt FROM empleado GROUP BY depto_no ORDER BY cnt DESC LIMIT 1;
    
answered by 11.06.2018 / 21:23
source