SQL practice: GROUP BY: One Answer Per Group

Chapter 10 · 13 questions · included in full access

  1. Question 1 · easy

    Count the orders per status.

    Solve it in your browser
  2. Question 2 · easy

    Count the customers per customer_type.

    Solve it in your browser
  3. Question 3 · medium

    Find the average salary per role, and show the headcount beside it.

    Solve it in your browser
  4. Question 4 · medium

    Count the branches per region.

    Solve it in your browser
  5. Question 5 · medium

    Find the total quantity sold per product_id.

    Solve it in your browser
  6. Question 6 · medium

    Count how many products fall under each thickness_mm value. What happens to the accessories?

    Solve it in your browser
  7. Question 7 · medium

    Count the orders per branch, counting only Delivered ones.

    Solve it in your browser
  8. Question 8 · medium

    For each customer_type, show how many customers there are and the earliest signup_date.

    Solve it in your browser
  9. Question 9 · medium

    For each branch, show total orders, delivered orders and cancelled orders as three separate columns.

    Solve it in your browser
  10. Question 10 · medium

    Count how many employees report to each manager_id.

    Solve it in your browser
  11. Question 11 · medium

    Find the total revenue per product_id from order_items (quantity × unit_price).

    Solve it in your browser
  12. Question 12 · hard

    Why does SELECT branch_id, order_date, COUNT(*) FROM orders GROUP BY branch_id; fail? Fix it by aggregating order_date with MAX() as latest_order so each branch has one summary row.

    Solve it in your browser
  13. Question 13 · hard

    Fix this query so it correctly counts the number of products in each category.

    Solve it in your browser

These questions are part of full access.

The first chapters of every track are free. Full access is a one-time payment.

See pricing