RienSQL
TASK #201 · Hard

The wrong employees ended up among department leaders

Your brief
The report must show employees whose closed deals total is above the average for their own department. The department average is taken only over employees who have closed deals.

The query runs and the numbers look plausible, but the selection is skewed: it picks up employees from departments with large deals, while the leaders of departments with more modest totals fall out of the report.

Output name (employee name) and total_amount (value of the deals they closed).
Expected columnsname total_amountCompany
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
departmentsid, name
employeesid, name, department_id, manager_id, salary, hired_at
customersid, name, registered_at
ordersid, customer_id, employee_id, amount, created_at
loginsuser_id, logged_at