Sitemap
Press enter or click to view image in full size

Member-only story

SQL Rolling Sum PART — 1

--

for part 2 please find the link

Interview Questions

Rolling Sum (Moving Sum) is one of the most frequently asked SQL Window Function topics in data engineering, analytics, and business intelligence interviews.

In this article, we will look at different scenarios, the questions an interviewer may ask, and how you can answer them correctly.

Interview Scenario

Interviewer asks:

You have a table containing daily sales transactions:

Press enter or click to view image in full size
Press enter or click to view image in full size

Write an SQL query to calculate:

  • Sales total for the current day and previous 2 days
  • Sales total for the current day and previous 6 days
  • Sales total for the current day and previous 29 days

These are called 3-day, 7-day, and 30-day rolling sums.

SQL Query

SELECT
sale_date,
amount,

--

--

HICK CORP
HICK CORP

Written by HICK CORP

This blog is about everything about BIG DATA AI and VFX, AI, MATHS, VISUALIZATION