No video

SQL Running Total | Advance SQL | Rolling N months SUM, AVG, MIN, MAX

  Рет қаралды 22,467

Ankit Bansal

Ankit Bansal

Күн бұрын

In this video we will learn how to find running/rolling calculations in SQL. This is very important concept and very frequently used in analytical projects.

Пікірлер: 55
@ianpropst-campbell6028
@ianpropst-campbell6028 2 жыл бұрын
Thank you for your helpful explanation of rolling calculations!
@sumksa
@sumksa Жыл бұрын
Thank you so much. May you have all the success in your life 🙏🙏
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you 🙏
@Aarohi_Zara
@Aarohi_Zara Жыл бұрын
select year(order_date), month(order_date), sum(sales) , sum(sum(sales)) over(order by year(order_date), month(order_date) rows between 2 preceding and current row) , avg(sum(sales)) over(order by year(order_date), month(order_date) rows between 2 preceding and current row) , max(sum(sales)) over(order by year(order_date), month(order_date) rows between 2 preceding and current row) , min(sum(sales)) over(order by year(order_date), month(order_date) rows between 2 preceding and current row) from orders group by year(order_date), month(order_date) order by 1, 2
@kanchidoshi6907
@kanchidoshi6907 2 жыл бұрын
Good content. Can you please make more business scenario specific videos?
@ankitbansal6
@ankitbansal6 2 жыл бұрын
sure
@fozantalat4509
@fozantalat4509 2 жыл бұрын
Hello Ankit, My name is Fozan I'm from Pakistan , your videos are very helpful please also make assignment questions, so that we can test our understanding.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Hi Fozan, Good to know my Pakistan friends are getting some benefit out of my videos. I will do that 🙂
@TienDuong-ck4jf
@TienDuong-ck4jf 3 ай бұрын
Thanks for your clear instruction :D
@ankitbansal6
@ankitbansal6 3 ай бұрын
You're welcome!
@DeshaKannada
@DeshaKannada 3 ай бұрын
Great 🎉
@mr2262
@mr2262 Жыл бұрын
How to calculate the prior rolling 12 months average (current year = 2023, prior = 2022) -- I tried this: rows 24 preceding and 12 preceding
@abhishekarora1
@abhishekarora1 2 жыл бұрын
Does proceeding keyword is specific to Microsoft SQL Server or it would work across different RDBMS?
@ankitbansal6
@ankitbansal6 2 жыл бұрын
It works across most of the databases
@abhishekarora1
@abhishekarora1 2 жыл бұрын
@@ankitbansal6 thanks for quick reply!
@sudarshanthota4444
@sudarshanthota4444 2 жыл бұрын
Nice video 👍
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Thank you 😊
@mgopinath9080
@mgopinath9080 5 ай бұрын
Amazing😍
@ankurrunthala
@ankurrunthala Жыл бұрын
Very good explanation 🙂
@ankitbansal6
@ankitbansal6 Жыл бұрын
Thank you 🙂
@utkarshtrivedi9949
@utkarshtrivedi9949 2 жыл бұрын
Also it will be very helpful if you can provide the data with each video to practice it also.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Okay
@explorer_baba2750
@explorer_baba2750 2 жыл бұрын
Hi Ankit, how can we find rolling sum without using any windows function . Today, One interviewer has asked me this question. If anyone has any idea can share their thoughts.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Can be done using self join
@SunilKumar_67
@SunilKumar_67 4 ай бұрын
I am working on writing a query which will give the number of hours left on starting day and it should gradually decrease towards end day and reach zero. Can you please create a video for this?
@ankitbansal6
@ankitbansal6 4 ай бұрын
24- hour(sysdate)
@amangupta1959
@amangupta1959 2 жыл бұрын
Hi Ankit, Could you please provide data for this tutorial? I practice side by side as I go by the video. Thanks in advance.
@ankitbansal6
@ankitbansal6 2 жыл бұрын
You can download data from below link: drive.google.com/drive/folders/1Dc81McsB4lp1JUIwssDmmOaw6Z7rBK8T?usp=sharing In below video I have explained how to import the data: kzfaq.info/get/bejne/ja-jg9yK26u6Ypc.html
@amangupta1959
@amangupta1959 2 жыл бұрын
@@ankitbansal6 thank you
@sashipanda3405
@sashipanda3405 2 жыл бұрын
how can we apply the same logic in postgre please help
@sashipanda3405
@sashipanda3405 2 жыл бұрын
adding to above if there are year,month,weeks column
@mithunnambiar1433
@mithunnambiar1433 2 жыл бұрын
Hi Ankit, A request... Could you please provide the schema of this query?
@ankitbansal6
@ankitbansal6 2 жыл бұрын
You can download superstore data from this link drive.google.com/drive/mobile/folders/1Dc81McsB4lp1JUIwssDmmOaw6Z7rBK8T?usp=sharing
@sachinkumargupta5660
@sachinkumargupta5660 2 жыл бұрын
Awsome
@utkarshtrivedi9949
@utkarshtrivedi9949 2 жыл бұрын
Please make a video on NTILE, LAG and LEAD function also
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Sure
@Ajaybchaudhari
@Ajaybchaudhari 18 күн бұрын
1:03 & 5:51 what is three sum?
@definitesquare
@definitesquare 8 күн бұрын
The column rolling_3_sum contains the sum of (that month, prev month and prev prev month)
@harishkanta3711
@harishkanta3711 Жыл бұрын
Ankit bhai what does unbounded preceding and current following give.
@ankitbansal6
@ankitbansal6 Жыл бұрын
Running sum
@harishkanta3711
@harishkanta3711 Жыл бұрын
@@ankitbansal6 thank you
@shobhitsharma2137
@shobhitsharma2137 Жыл бұрын
how to get dataset
@shreyashchoudhary6827
@shreyashchoudhary6827 2 жыл бұрын
please provide data ,create and insert stmt ,github or here
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Provided in today's video
@yatinshekhar787
@yatinshekhar787 11 ай бұрын
9/142
@vishalsonawane.8905
@vishalsonawane.8905 4 ай бұрын
Please add the data
@vandanaK-mh9zo
@vandanaK-mh9zo 8 ай бұрын
with cte as ( select datepart(year, order_date) as sales_year, datepart(month, order_date) as sales_month, sum(sales) as sales From cust_orders group by sales_year,sales_month) select *, sum(sales) over (order by sales_year asc, sales_month asc rows between 2 preceding and current row) as rolling_sum, min(sales) over (order by sales_year asc, sales_month asc rows between 2 preceding and current row) as rolling_min, max(sales) over (order by sales_year asc, sales_month asc rows between 2 preceding and current row) as rolling_max, avg(sales) over (order by sales_year asc, sales_month asc rows between 2 preceding and current row) as rolling_avg from cte;
@sky4223
@sky4223 2 жыл бұрын
Sir Hume chotte bacche ko dekhna hai
@ankitbansal6
@ankitbansal6 2 жыл бұрын
Haha 😃
@sky4223
@sky4223 2 жыл бұрын
Kab dikhaoge
这三姐弟太会藏了!#小丑#天使#路飞#家庭#搞笑
00:24
家庭搞笑日记
Рет қаралды 92 МЛН
Happy birthday to you by Tsuriki Show
00:12
Tsuriki Show
Рет қаралды 12 МЛН
7 Days Stranded In A Cave
17:59
MrBeast
Рет қаралды 96 МЛН
How to Crack Data Engineering Interviews
20:41
Ankit Bansal
Рет қаралды 11 М.
SQL Case When Statement | SQL Fundamentals | SQL Tutorial
8:09
Ankit Bansal
Рет қаралды 10 М.
SQL Query | How to calculate YTD and MTD totals | Window Functions
16:01
Learn at Knowstar
Рет қаралды 41 М.