Advanced SQL Challenge: Using Windows Function

365 Days of Daily Challenge: Day 94

I went to work in the office today after almost like 1 year. It felt strange but it was nice meeting some of my colleagues in the office. I feel lucky since I can decide whether I want to work from home or work from office.

I solved an advanced sql challenge today which quite easy.

Advanced SQL Challenge

WITH temp AS (
Select '7/1/2018' AS Dates, 100 AS Quantity FROM Dual Union All
Select '7/2/2018' AS Dates, 75 AS Quantity FROM Dual Union All
Select '7/3/2018' AS Dates, -150 AS Quantity FROM Dual Union All
Select '7/4/2018' AS Dates,  50 AS Quantity FROM Dual Union All
Select '7/5/2018' AS Dates, -50 AS Quantity FROM Dual
)

SELECT SUM(Quantity) OVER (ORDER BY Dates) AS Running_Sum FROM temp;

Leave a comment