"top" with MAX in mysql [closed]

1

I need to make an appointment that returns the top 3 salaries of public employees, by state. example that should return:

fulano     850 RJ
ciclano    800 RJ
beltrano   700 RJ
joao      1000 SP
maria      900 SP
pedro      200 SP

I used MAX in salary and grouped by state, however, only the highest salaries of each state appear. If anyone knows, please help me.

    
asked by anonymous 20.07.2016 / 13:23

1 answer

0
select * from tb_funcionarios group by fu_estado ORDER By fu_salario DESC LIMIT 3.

The trick is to use the ORDER BY field DESC because it will sort in the descending order and you put the LIMIT 3 it will only display the first 3

    
20.07.2016 / 14:26