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

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…

Contents