1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to BigQuery

Connected

Exercise

RANK and LEAD/LAG

Rankings allow you to rank your data in any particular order, while the LAG and LEAD functions allow you to look forward or backward in the window of our query. These tools help you to create compelling reports and more complex analytical functions in the case of LAG/LEAD. Here, you will put these into practice with our data.

Instructions 1/2

undefined XP
  • 1
    • Complete the CTE to group customers by total amount spent, then use the RANK function to rank customers by this total under the alias all_items.
  • 2
    • Create a query that shows each item's current, previous, and next value in an order, grouped by customer_id.