SQL Window Function | How to write SQL Query using RANK, DENSE RANK, LEAD/LAG | SQL Queries Tutorial
Вставка
- Опубліковано 8 чер 2024
- This video is about Window Functions in SQL which is also referred to as Analytic Function in some of the RDBMS. SQL Window Functions covered in this video are RANK, DENSE RANK, ROW NUMBER, LEAD, LAG. Also, we see how to use SQL Aggregate functions like MIN, MAX, SUM, COUNT, AVG as window function.
This video is focused on teaching how to write SQL Queries using different window functions or analytic functions. We go through the syntax of using rank, dense_rank, row_number, lead, lag and max functions as window function.
Over clause is explained in detail in this video. Over clause is used in SQL when we need to use window function. Inside Over clause, we also use Partition By clause and also Order by clause.
Partition By clause is used to specify the column based on which different windows needs to be created.
The window function you learn in this video is applicable to any RDBMS since these functions are commonly used across most of the popular RDBMS such as Oracle, MySQL, PostgreSQL, Microsoft SQL Server etc.
Download all scripts and Queries used in this video from below link:
techtfq.com/blog/sql-window-f...
Click on the "Download SQL Script" button to download scripts.
Timestamp:
00:00 Intro
01:33 Understanding Aggregate function
03:16 Syntax to write SQL Query using Window Function
06:33 ROW_NUMBER() Window Function in SQL
11:57 RANK() Window Function in SQL
15:43 DENSE_RANK() Window Function in SQL
17:10 Difference between RANK, DENSE RANK and ROW NUMBER in SQL
17:59 LEAD() and LAG() Window Function in SQL
I hope this video was helpful and gives you a good understanding of how to write SQL Queries using window functions or analytic functions. If you liked what you saw, then please make sure to like, subscribe and comment any feedback you may have.
Also please do not hesitate to share the video with your friends and colleagues who may be interested in learning SQL
🔴 WATCH MORE VIDEOS HERE 👇
✅ SQL Tutorial - Basic concepts:
• SQL Tutorial - Basic c...
✅ SQL Tutorial - Intermediate concepts:
• SQL Tutorial - Interme...
✅ SQL Tutorial - Advance concepts:
• SQL Tutorial - Advance...
✅ Practice Solving Basic SQL Queries:
• Practice Solving BASIC...
✅ Practice Solving Intermediate SQL Queries:
• Practice Solving INTER...
✅ Practice Solving Complex SQL Queries:
• Practice Solving COMPL...
✅ Data Analytics Career guidance:
• Data Analytics career ...
✅ SQL Course, SQL Training Platform Recommendations:
• SQL Course / Training
✅ Python Tutorial:
• Python Tutorial
✅ Git and GitHub Tutorial:
• Git and GitHub
✅ Data Analytics Projects:
• Data Analytics Projects
THANK YOU,
Thoufiq
Watching his videos I successfully cracked two interviews of Amazon for Data Engineer role , and secured internship.
You explain every things in a clear English, I think this is one of the finest tutorial on UA-cam... Keep it Up
Thank you Raheem 🙏🏼
Glad you liked it 🙂
One of best demonstration with absolute clarity about the windowing concept. Thank you for the simplest/easiest explaination of this complex concepts.
Thank you so much 🙏🏼
Means a lot to receive such positive feedback ☺️☺️
This was super helpful and easy to follow! I'm currently studying SQL and this was the best explanation of windows functions I came across. Would love to see more videos on SQL!
Thanks a lot for such kind words 🙏🏼
So glad to hear that you found it useful ☺️
Agree!
Thank you 🙏🏼
Thank you so much it is helpful please make more videos on functions in oracle sql
Thank you 🙏🏼 sure will do
I would have clear the interview today, if I had watched this before ..
Sorry to hear you didn’t clear this time but I hope you get a better opportunity very soon ..
Thank you for liking my video🙏🏼
@@techTFQsir I want to study your python courses if under my budget Please let me know sir. Thank you
Same story here
I was also asked the same question of finding the top 3 employees from each dept. Sad, I didn't know window functions then.
This tutorial, right here, is one of the best to learn what Window Functions are
Thank you Utkarsh for such encouraging feedback 🙏🏼
So glad you liked it..
The most clearest way of explaining window function! Bravo!
amazing. i’ve been struggling with window functions and your 25min video has explain it better than a whole day of course material. thanks so much!!!!
This is the best video I’ve found explaining window functions. Thank you for your help! I really appreciate it
Thanks a lot for the positive feedback 🙏🏼
Much appreciated and so glad the video helped ☺️
I am a new SQL learner. So, I saw many videos on SQL tutorials. But, I found your one very helpful and effective. I was struggling with the Window function so hard that I thought I would give up learning SQL. But, your video makes it very simple to me. I am really impressed with your videos. Keep it up.
Thank you so much buddy 🙏🏼
It means a lot to receive such positive feedback ☺️
I am so glad this helped you..
This is the most straightforward version of the window function I ever learned. Super helpful! Please teach more advanced SQL language in this channel.
You are an absolute legend for explaining window functions in detail. Thank you so much.
Hey brother, Just love the concepts you cover. I could easily understand these window functions. Credits to your teaching skills. You make it so simple and fun. Since i primarily work on SQL, this video was really helpful. Please make more videos on other window functions/advance SQL concepts. Cheers ✌🏻
Thank you Shahil ❤️❤️
Good to know you benefited from this..
Sure will try to cover other functions in another video..
I've search a lot about window function on Google and UA-cam but this tutorial is far better than others. It has helped me a lot . What a easy way to explain.✌
Thank you Harsh. glad you liked it :)
This was an extremely helpful review of all the listed window functions. The clear walkthrough of each function and how they interact with each other was done exceptionally well. I was having issues using the lag function correctly and this answered every one of my questions. Looking forward to watching more of your SQL videos! Subscribed!
Thank you!
Your welcome Jonathan ..
I am glad to read your feedback ☺️
Your new subscriber. One of the best channel I came across in learning SQL. You deserve much more subscribers
Woww you made my day by such positive feedback ☺️.. thanks a lot and so happy this video helped you 🙏🏼
@@techTFQ Thanks to you too for making good contents. Wishinh you all the luck
@@jollypareira688 thank you again 🙏🏼
This gentleman is very practical and a good teacher of SQL. It feels like in person lesson.
Thank you so much Isaac 🙏🏼
Perfectly Splendid ❄️☕❄️ .
I am newly deployed data engineer and I loved how you crafted this concept in simple approach
Thank you , glad this helped
This has become my reference link to revise window functions fundamentals before any sql interview round. Thanks much !
Absolutely brilliant and crisp way of explanation. I had never studied about window functions so far and I just checked your tutorial video to learn, I got crystal clear clarity about window functions - their syntax, usage, scenarios where it can be used. Truly impressed with your teaching skills. Keep teaching, you are doing a great job.
It was an clear explanation with understandable examples, which will be very helpful especially for beginners like me 👏
This tutorial, right here, is one of the best to learn what Window Functions are.
Background slow music is awesome.
Thank you Amaresh 🙏🏼
Glad you liked it..
I'm preparing for an SQL intensive position and this is a phenomenal overview of windows functions. You provide an overview of the logic then how to apply them to real business questions. Great job!
I have been struggling with understanding window function for a really really really long time. But just one video of yours has made the concepts crystal clear to me. Thanks a lot!
Awesome awesome 👌 You are simply the best, explaining, intention, dedication Perfection. Keep it up. God bless you. Amen🙏
No words to thank you..
still thank you to you for everything 🙏🏼❤️
Great training, straight to the point, clear examples.
Thank you 🙏🏼
Glad you liked it..
Your tutorial helps a lot! Make window function so easy and simple! Thank you!
You are an amazing tutor, My first appreciation commend to someone
Please make another video for the remaining parts. Thank You!
Thank you Suman.. will do it..
LOVE YOUR VIDEOS TFQ ! GREAT WAY OF EXPLAINING AND GREAT EXAMPLES ! THANK YOU AGAIN !
WE DONT MIND IF THE VIDEOS ARE LONG, THEY ARE HIGH QUALITY !
WE DONT CARE IF THERE IS BACKGROUND MUSIC OR NOT, THE WAY YOU EXPLAIN MATTERS THE MOST !
Thank you Dhruv once again 🙏🏼
Happy to know you liked them
Very well done, thank you. I’ve always just ignored Rank because I thought row number does the exact same thing but you’ve helped realize where rank can really be useful.
This is the best and most comprehensible video I have seen on Windows Function since I have been practising SQL.
Thank you Omotola 🙏🏼
Glad this helped
Amazing explanation. I was really pushing back on this part of SQL as i found it very difficult to read from books and blogs but you made it easy man. Thanks a lot !!
So glad to hear that ☺️☺️
Am I right to say that the problem statement - fetch top 3 employees in each department earning the max salary - can be solved using row_number() as well?
Great. So proud of your intelligence. Your talent of teaching in such simple & understanding way is amazing 👍 Keep growing.
Thank you dearest cheeb ❤️
this one video explains everything you need to know about window functions in SQL!!
Wonderful and straight to the point! Great examples!
Perfectly Explained !! No flaws
Thank you palaniappan 🙏🏼
Glad this helped..
Awesome! would love to see another video on other window functions. Please do another one!
Thanks a lot 😃
Will be doing another video on other window functions soon..
Before attend any interview I will definitely check your this video.. Thanks
taufeeq the clarity of your teaching is supreme..thank you..
You have the gift of teaching complex stuff in a very friendly and simple manner… best wishes for a great future
Thank you Shiva 🙏🏼
Couldn't be explained better. Great work.
Thank you so much 🙏🏼
Glad you liked it ☺️
This is a masterclass for SQL window's function, great explanation!
Clear and concise demonstrations. Thank you for this!
Such a helpful video to understand windowing functions. That was really helpful.
Thank you 🙏🏼
So glad u liked it 🙂
Bro simply your lecture is amazing
Thanks a lot 🙏🏼 glad you liked it ☺️
The the the best explanation one can ever go through in a most easiest way ,thanks aton
The clearest explanation in UA-cam.
Great!
Thank you 🙏🏼
Best Video on Window Functions that I have watched till now💖💖💖💖
Thank you so much 🙏🏼
Glad this helped ..
@@techTFQ I have recently cleared most of SQL rounds because of your video on Window Functions, I request you to continue the good work and plz do some UA-cam shorts on advanced level SQL questions, as they could be both interesting to watch as shorts and useful as brain teasers if someone is attending interviews.
Awesome news bro.. am so glad my videos helped you to find a job.®️☺️👌👍
As for shorts, really good idea, let me consider it..
Enjoying every detail.. and as we know every detail matters ..and not many would present with all details.. u r amazing bro..God bless u..
Thank you Ani for taking your time to appreciate my work 🙏🏼
Truly appreciate the feedback 🙂
In 24 minutes you have explained to me window functions in a way better than spending 4 hours in Datacamp
Possibly the best tutorial on windows functions!
Thank you so much! That's an amazing explanation!
Your welcome Luiz 🙏🏼
Glad this helped ..
Really good, Thank You!. You should do more SQL tutorials, specially in a structured fashion and starting from basics.
Thank you 🙏🏼
Glad you’ve liked this video.
Yeah, I might consider making a complete Sql tutorial playlist from scratch in the near future
Thanks for explaining so clearly. Its so easy to understand the window functions. Keep it up!!
thank you sooooo much for this video.... I have commented on only 8-10 videos in my whole youtube life and you are one of them... superb explanation...
I was struggling so much with these window functions, thank you truly for this great video lecture. I've never ever commented to any video but this video right here deserves a respect 👏
Thank you so so much Khushboo for this amazing feedback 🙏🏼
I am so glad you took your time to comment on this video.. it feels great to know that this video has helped you understand the concept ☺️☺️
@@techTFQ are you planning to make videos on machine learning too?
Yes I plan to do it in the near future..
in the next few weeks will focus on covering some data science concepts and then hopefully will cover machine learning too..
Thanks a ton in making these concepts so easy for us to understand . your teaching skills are just outstanding.Please let us know if you have a complete course.
Am I right to say that the problem statement - fetch top 3 employees in each department earning the max salary - can be solved using row_number() as well?
Hello, Its an excellent channel for SQL. I was asked the same questions in my interview and I watched this video just before it. Love the content. Thank you
This is the best video I've ever came across for the window function. Thank you!!!
I can't tell you how helpful was this
Thank you Satyam 🙏🏼
Glad this helped ..
damn Bloody good. Just loved the explanation and the content. you did save a ton of time for me. wish you all the best.
Thanks a lot for your kind words ☺️☺️
So glad it helped 🙏🏼
you are the best ,explains everything clearly .I am so thankful 🙏
Best demonstration so far!!! THANK YOUUU!!
Dear brother...the way you are explaining the things is very easy to understand.. day by day i m increasing my knowledge on SQL...thanks for your all efforts and i wish you all the best!
well taught and easily understood could you do video on other window functions and stress more on use cases
Thanks a lot for your kind words 🙏🏼
Sure will consider your feedback ..
Very good explanation 👌👌👌👌👌
I owe you a debt of gratitude. Thanks for clarifying so many things for me. At work I inherited a stored procedure that utilized many of the functions you covered. Was lost understanding it and your video turned on all the lights in the house! I am now a subscriber and will go back to the at h your library!!! Take care and stay safe!!
Thank you Jose 🙏🏼
So glad this video helped you ☺️
To be honest, you tech better than some of professors in college. I will watch every of your videos. Thank you.
Thank you! Very helpful for someone who just decided to pick up window function.
Glad it helped
You saved my hours of classes to understand such complex concepts in such a short span of time... Thanks bhai...
Welcome:)
I always searched for the syntax of window functions but after your explanation I dont find that necessary because you explained it very well.. 🙏
glad this helped
Clear and concise , thank you very much!
So well explained! Couldn't have been any better!
SUPER clear. much better than some of the other tutorials that I saw out there. Thank you very much!
Thank you Alicia :)
Explained the clearest I've see so far. Thank you!
Glad you liked it ☺️
This was very very helpful to me. I'm currently learning MYSQL and this was the best explanation of windows functions I came across. I would love to see more videos on MYSQL!
Amazing explanation! Was struggling with window functions - this was really clear! Many thanks to you Sir! :)
Thanks, sir. You are an amazing guy. Please make courses on SQL and also add real-world coding challenges.
This is the best video for explaining the Window functions in SQL, I really do not know about them before watching this video.
Well explained by you.
pedagogical value of vid is sublime. hands down man of the match.
Absolutely excellent tutorial, could not have been better!
This kind of teaching, which relates everything, this is what is needed!! Feeling really grateful for finding this channel where concepts are not just told as they are but their purpose is explained by building upon the examples, step by step.. :)
Not a ton of VERY clear advanced SQL Windows functions out there - easy to understand and really clear! Thank-you for the work
Glad you liked it Matthew
Thank you! you just removed all of my troubles! you explained it very clearly and it was super easy to follow.
Cant believe i havent been using these functions!!!..Thank you..this was great!
Best explaination!! I have watched and read 1000s of videos/articles but was unable to grasp window function concepts. This Video really gave a detailed breakdown of how Window Functions work as well as their use cases. Love from Pakistan
These people have literally made youtube platform a university, where you can learn anything for free. ❤
This is the greatest SQL video I have ever seen. Thank you sooooo much!
Thank you so much for such an amazing compliment 🙏🏼
So glad to know the video helped ..
Bro Honestly this is the best video on analytical functions on youtube. In one go, I understood all the functions completely.
Glad to hear that buddy
thank you. It was masterclass teaching at its peak.
I don't comment in UA-cam videos normally.
But for this one, I have to!
The best video for me when it comes to window functions.
Thanks techTFQ!
Thanks so much for clear simple explanation !
thank you my Indian brother. The tutorial was very clear!
my friend your channel is a good mine
i am new to SQL and you are helping alot
thanks alot
Your a best tutor i have come across sir.keep going
This was excellent. So simple. Thank you!
It was really helpful video i went through it just 1 day before my interview day and I was able to understand the concept .
SQL is knowledge, but to know how to teach it in such a beautiful and beginner friendly way, is an art! Bravo for this video. Not only I subscribed to your channel I'll present it to everyone who needs a good
course in SQL. 👏👏👏👏👏👏
You are one of very best. You are very knowledgeable. Thank you so much!
Your welcome Vu Phan 🙏🏼
Glad you liked the video