Join tables like an analyst
Combine customers, orders, products and people into one answer, find what is missing with LEFT JOIN, and keep your totals honest when tables multiply rows.
Start course→ 02
→ 03
Your exercises
01The orders table only stores customer_id, but the account manager wants names. For every order placed in September 2026 (any status), return order id, order_date and the customer's name. Sort by order_date, then by order id.
Sales wants to invite its five most valuable customers to a launch event. Return customer name and paid revenue (quantity × unit_price, paid orders only) rounded to 2 decimals for the top 5 customers, sorted by revenue from high to low. Treat each customer id as one customer.
Some order lines were sold below the catalogue price. For paid orders only, compare each line's unit_price with the product's list price (products.price). For every product that was sold at a discount, return product name and the total discount given in euros ((price − unit_price) × quantity, summed), rounded to 2 decimals. Sort by total discount from high to low.
Marketing wants to send a welcome discount to people who created an account but never placed a single order (of any status). Return name and signup_date of those customers.
HR is preparing the hiring plan and needs the headcount of every department, including departments that have nobody yet. Return department name and number of employees, sorted by number of employees from high to low, then by department name A to Z.
The employees table stores each person's manager as manager_id, which points to another row in the same table. For an org chart export, return every employee's name, their title, and their manager's name. The CEO has no manager: keep her in the list with NULL as manager name.
The board wants a scorecard per sales channel. Using paid orders only, return channel, number of paid orders, and paid revenue (quantity × unit_price) rounded to 2 decimals. Sort by revenue from high to low.
For the salary review, HR wants everyone who earns strictly more than the average salary of their own department. Return employee name, department name, salary, and the department's average salary rounded to 0 decimals. Sort by department name A to Z, then by salary from high to low.