mysql - Selecting Top 10 Employee Salaries -


i have database salaries of employees.

here salaries table fields:

emp_no int(11) salary int(11) from_date date to_date date 

i'm trying top 10 employee salaries, non-duplicate employees. code below can maximum salary emp_no, from_date , to_date defaulting earliest date values emp_no.

select emp_no, max(salary) salary, from_date, to_date salaries group emp_no order salary desc limit 10 

i assumed group by keep values of dates matched salary , emp_no, after thinking bit doesn't make sense so.

any how correct date values appreciated.

first table contain top 10 salaries.

then check original table see row matches emp_no , salary dates.

select s.*       (select emp_no, max(salary) salary      salaries      group emp_no      order salary desc      limit 10    ) maxsal inner join salaries s    on maxsal.emp_no = s.emp_no   , maxsal.salary = s.salary 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -