15 schema + canonical query recipes. Click any to see the schema and the right query.
Return the top 2 sales reps in each region by total amount. If two reps tie, both should appear and the next rep should be skipped (classic 1, 2, 2, 4 ranking).
Return every customer who has never placed an order. Note that orders.customer_id is nullable because guest checkouts are stored in the same table.
Return each day with a running total of revenue from the earliest day through that day, ordered by day.
Return the median salary per department in PostgreSQL. Use a continuous median (interpolate between the two middle values for even-sized groups).
Return the names of employees who earn strictly more than their direct manager. Employees with no manager should not appear.
Given a CEO with manager_id IS NULL, return every employee in the org along with their depth (CEO = 0, direct reports = 1, etc.).
Return the names of departments that have at least 3 employees, alphabetically sorted.
Return a single row with two columns: total_users (every row) and users_with_phone (rows where phone is set).
For a report, return every customer along with their order total. Customers who have placed no orders should still appear (with total = 0).
Return the names of products that have NEVER been returned. The returns table can contain rows with product_id IS NULL.
Return each unique (user_id, page) pair along with the number of views for that pair. Order by views desc.
Return every email address that is associated with more than one user row, along with how many times it appears.
In PostgreSQL, return the user_ids of people who started at least one session strictly AFTER their signup and within 7 days of signing up (i.e. signup < session <= signup + 7 days).
In PostgreSQL, pivot 2025 orders into one row per region with columns q1, q2, q3, q4 holding the sum of total for that quarter.
In PostgreSQL, set status = 'inactive' for every user who has placed no orders in the last 365 days (including users who have NEVER placed an order). Update only users currently not already inactive.