Identify Department for Reduction
 

Select departments that have no more than 5 employees. From these, choose departments based on the descending order of the total salary of its employees. In case of a tie in total salary, prioritize the department with the greater number of employees. If still tied, prioritize by the smallest department id. From the resulting list, eliminate departments in even positions, leaving only those in odd positions for further consideration. The resulting table should contain columns for department name, number of employees, and total salary, sorted as described.

These are the tables to query for this question:
playground.dept
  • id int
  • name string
playground.emp
  • id int
  • full_name string
  • salary int
  • department int
Your answer should include these columns:
  • dep_name varchar
  • emp_number integer
  • total_salary integer

Querying is only for logged in users!

Write Your Query Here (you can run selections by highlighting!)

Query Results

No queries have been run yet.