Skip to content
SQLSimplified
Data AnalystQuestion 33 of 57

Predicting Next Rows (LEAD)

Problem

You are calculating the time elapsed between order occurrences. To prepare the analysis, retrieve customer_id, order_date, and the date of the customer's next order as next_order_date.

Database Schema

Table: customers

  • `customer_id` (INT): Unique identifier for the customer.
  • `first_name` (VARCHAR): First name.
  • `last_name` (VARCHAR): Last name.

Table: products

  • `product_id` (INT): Unique identifier for the product.
  • `name` (VARCHAR): Product name.
  • `price` (DECIMAL): Product price.
  • `category` (VARCHAR): Product category.

Table: orders

  • `order_id` (INT): Unique identifier for the order.
  • `customer_id` (INT): Foreign key referencing the customer.
  • `order_date` (DATE): Date of the order.
  • `amount` (DECIMAL): Total order amount.

Try It

Loading playground environment...

Hint

Solution