What does the following window function return for each row? SUM(sales) OVER (PARTITION BY region ORDER BY sale_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

SQL Data Analyst Medium

SQL Data Analyst — Medium

What does the following window function return for each row? SUM(sales) OVER (PARTITION BY region ORDER BY sale_date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)

Key points

  • The function is partitioned by region, so it calculates the running total separately for each region.
  • The ordering by sale_date ensures the running total is based on the chronological order of sales.
  • The ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW specifies the range of rows to include in the running total.

Ready to go further?

Related questions