Sobes.tech
Intern

SQL: list employees who are older than their manager (table employees with fields employee_id, department_id, is_chief, birthday).

sobes.tech AI

Answer from AI

To solve the task, it is necessary to compare employees' birth dates with their managers' birth dates. Assume that a manager is an employee with is_chief = true in the same department_id.

Example SQL query:

SELECT e.employee_id, e.department_id, e.birthday
FROM employees e
JOIN employees c ON e.department_id = c.department_id AND c.is_chief = TRUE
WHERE e.birthday < c.birthday;

Here, we join the employees table with the managers table by department_id, selecting employees whose birth date is earlier (i.e., they are older) than their manager's birth date.