Existence, sets and safe NULLs
Answer yes-or-no questions across tables with EXISTS, find missing relationships, combine lists with UNION, and keep missing values from corrupting reports.
Start course→ 02
→ 03
Your exercises
01Sales wants to check on business customers who have never placed any order, regardless of status. Return their name and email, sorted by name A to Z. Use the customer ID relationship, not a guess based on their email or signup date.
Customer success wants one row per customer who has at least one refunded order. Return customer name and country, sorted by name A to Z. A customer with several refunds must still appear only once.
Marketing has two overlapping target lists: business customers, and customers in Germany. Combine them into one list with customer name and email, sorted by name A to Z. Anyone in both lists should appear once, not twice.
Operations wants a two-row scorecard with status and orders: one row for paid orders and one for refunded orders. Include their actual counts, sorted by status A to Z. Use UNION ALL to combine the two independently counted groups.
The CRM export cannot accept blank city values. Return each customer name and their city, replacing a NULL city with the text 'Unknown'. Sort the 20 customers by name A to Z, then by customer ID to keep same-name rows stable.
Finance needs every department, including Research with no employees. Return department name, budget, total employee salaries (0 for an empty department), and salary spend as a percentage of budget rounded to 1 decimal. Sort by department name A to Z.