SQL practice: LAG and LEAD

Chapter 24 · 9 questions · included in full access

  1. Question 1 · easy

    For each customer, show each order date with their previous order date.

    Solve it in your browser
  2. Question 2 · easy

    For each customer, show the number of days between each order and the previous one.

    Solve it in your browser
  3. Question 3 · medium

    For each customer, show each order with the next order date.

    Solve it in your browser
  4. Question 4 · medium

    Find each customer's most recent order using LEAD being NULL.

    Solve it in your browser
  5. Question 5 · medium

    For stock transfers, show each transfer with the previous transfer's quantity.

    Solve it in your browser
  6. Question 6 · medium

    Show monthly order counts with the previous month's count beside each one.

    Solve it in your browser
  7. Question 7 · medium

    Show monthly order counts and the change from the previous month.

    Solve it in your browser
  8. Question 8 · hard

    For each employee within their branch, ordered by hire date, show who was hired just before them.

    Solve it in your browser
  9. Question 9 · hard

    For each order, show the same customer's previous order date (NULL for their first order). First orders show another customer's date instead. Fix it.

    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