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
Post a Comment