Calculating A Running Total With SQL

preview_player
Показать описание
SQL is the language of data. It can be used to answer countless questions in any company (unless that company still runs 100% off mainframes).

The ubiquity of data makes SQL one of the most utilized technical skills whether you are a data engineer, analyst, or data scientist.

One of the problems you may have to solve is calculating a rolling sum. There are many ways to approach this problem. You can use an analytic function, a self join, a subquery and even simply design.

If you have any questions or comments on SQL please feel free to send them!

Also, if you have any problems you want solved with SQL please let us know.

Problem Solving With SQL
Рекомендации по теме
Комментарии
Автор

you didn't sum in second example which is without analytic function.

humayounkabir
Автор

The explanation is really great. Code to create the table shown in this video :

Create Table f_FoodTruck_Transactions
(
food_truck_id int,
paid_amount float,
date_of_purchase date,
datecreated datetime default current_timestamp
);

Insert into f_FoodTruck_Transactions values
(1, 10.2, '2018-01-01', '2018-01-01'),
(1, 36.32, '2018-01-02', '2018-01-02'),
(1, 120.19, '2018-01-03', '2018-01-03'),
(1, 130.24, '2018-01-04', '2018-01-04'),
(1, 210.42, '2018-01-05', '2018-01-05'),
(2, 50.9, '2018-01-01', '2018-01-01'),
(2, 110.52, '2018-01-02', '2018-01-02'),
(2, 50.29, '2018-01-03', '2018-01-03'),
(2, 70.12, '2018-01-04', '2018-01-04'),
(2, 90.2, '2018-01-05', '2018-01-05'),
(2, 110.33, '2018-01-06', '2018-01-06')

tejagoud
Автор

Where's the video for aggregating I'm trying to work out strategies for rolling sums with aggregate table

Gbyrd
Автор

Thank you so much for the explanation 😇

sharu
Автор

cool stuff. The explanation is very clear. Good job!

eee
Автор

WHat if you want to do this to unique food_truck_ids and sort by date of purchase

chiedoziie