"top" with MAX in mysql

Asked

Viewed 77 times

1

I need to make a query that returns the 3 highest salaries of civil servants, per 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 Group by state, however, appears only the highest wages of each state. If anyone knows, please help me.

  • Group by Funcionario, Estado have you tried? This one of mine question is very similar to what you want but then I answered using the Min

  • Check this link, this might help: http://stackoverflow.com/questions/4775820/sql-give-me-3-hits-for-each-type-only

  • Camila, post your table and the query you tried please.

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 DESC field by which it will require in descending order and you putting the LIMIT 3 it will display only the first 3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.