Given a table 'employees'
employee_id | salary | department_id
-------------+--------+---------------
Only using SQL find all the variants of employee-transfers from one department to another, so that average salary in both 'departure' and 'arrival' department grew.
PS I was asked the question on a interview, which never gave an answer, and Google is of little help.
Best Answer
So you are looking for Employees that earn below the average in their current department but above the average in their prospective new department.
One possible way of getting all employee transfers that would meet this would be