Menu

SQL Running Total: Calculate Cumulative Daily Sales Using SUM() OVER() in Oracle SQL
📰

SQL Running Total: Calculate Cumulative Daily Sales Using SUM() OVER() in Oracle SQL

DEV Community: database·Kailas Warade·17 days ago
#IiG0RVRo
Long article (504 words) — no AI summary yet.
Reading 0:00
15s threshold

When working with sales data, you may come across a requirement to calculate how much revenue a business has generated up to a particular date.

For example, a sales manager may want to see daily sales along with the total sales accumulated from the beginning of the month.

This is called a Running Total or Cumulative Sum.

In SQL, we can calculate it easily using the "SUM()" window function with the "OVER()" clause.

In this SQL Challenge #105, let's see how to calculate a running total using Oracle SQL.

The Sales Table

Assume we have a table named "sales" containing daily sales information.

sale_date| daily_sales

01-Nov-2026| 1000

02-Nov-2026| 1500

03-Nov-2026| 800

04-Nov-2026| 2000

05-Nov-2026| 1200

Our requirement is to calculate the cumulative sales for each date.

Your Challenge

Write an SQL query to:

Display sale date, daily sales and running total.

Use "SUM()" to calculate cumulative sales.

Arrange records by sale date, from oldest to newest.

Add each day's sales to the previous running…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.