In this video we will see the concept of running sum(cumulative sum) and normal sum in sql.
Example for both running sum and normal sum are demonstrated in the video. Output of the same can be used for data visualization or dashboarding.
A running total is the summation of a sequence of numbers which is updated each time a new number is added to the sequence, by adding the value of the new number to the previous running total.
Running sum is calculated using the WINDOW function. Window functions applies aggregate and ranking functions over a particular window (set of rows). OVER clause is used with window functions. OVER clause along with aggregate function SUM is used to calculate cumulative sum.
"Thanks for watching. If you liked this video, make sure to subscribe for more!”
#dataprojecthub
#data_project_hub
Normal SUM we simply calculate the total using the SUM function and appropriate GROUP BY clause.
--DDL
--create table
create table sales_data(
sales_year varchar(512),
sales_quarter varchar(512),
quantity int,
amount int)
--insert values into the table
insert into sales_data(sales_year,sales_quarter,quantity,amount)
values('2020','2020_q1',150,2300),
('2020','2020_q2',180,2700),
('2020','2020_q3',260,4100),
('2020','2020_q4',100,1700),
('2021','2021_q1',210,3600),
('2021','2021_q2',90,1600),
('2021','2021_q3',120,2200),
('2021','2021_q4',220,3800),
('2022','2022_q1',140,2200),
('2022','2022_q2',190,3400)
“Thanks for watching. If you liked this video, make sure to subscribe for more!”
Feedbacks are always welcome!
Информация по комментариям в разработке