From the course: SQL Tips and Tricks for Data Science
Unlock the full course today
Join today to access over 23,100 courses taught by industry experts.
Window functions - SQL Tutorial
From the course: SQL Tips and Tricks for Data Science
Window functions
- [Instructor] So here, we're looking at window functions. And these are special functions that specify partitions and ordering for the purpose of aggregation. I think of these as arguments or ways of focusing our analysis in one particular segment of our data. The first case I want to bring up for using window functions is to focus on a partition. This is useful when you want to do something like compare a region's average sales volume to total sales volume. By using the partition by clause, you can specify exactly the scope of your aggregation. Another unique feature of window functions is the ability to reference previous rows within the same query. This is useful when you want to calculate the percent difference between discrete values, such as territories. The last example I think you'll find particularly useful is using window functions to perform year-to-date calculations. This uses a part of the over clause known…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
Retrieve data using SQL4m 18s
-
(Locked)
Join tables5m 44s
-
(Locked)
Filter data5m 33s
-
(Locked)
Aggregate data6m 29s
-
(Locked)
Window functions1m 54s
-
(Locked)
Subqueries4m 16s
-
(Locked)
Rolling calculations4m 48s
-
(Locked)
Analyze employee data4m 18s
-
(Locked)
Date and time functions5m 11s
-
(Locked)
Common table expressions5m 55s
-
(Locked)
Year-over-year calculations3m 26s
-
(Locked)
Finding ranks4m 9s
-
-