Skip to content
SQLSimplified
Data AnalystQuestion 50 of 57

Calculating Running Totals

Problem

The cash flow department wants to calculate the cumulative revenue earned day-by-day. Write a query to calculate a running total of the order amount sorted by order_date. Output order_date, amount, and running_total.

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