1. dbt Labs Developer Blog
"How to use window functions in SQL": This official guide explicitly states
"Window functions are a powerful SQL feature that can help you write cleaner and more efficient queries." It provides examples of calculating running totals and moving averages
noting that these functions "allow you to perform calculations that would otherwise require complicated joins and subqueries." This directly supports the claim that they reduce the need for these constructs and help optimize queries.
2. dbt Labs Documentation
"Refactoring SQL for modularity": In the section "Refactoring a query that computes market share
" the guide shows a "before" query that uses a subquery in a JOIN to calculate a total denominator for a percentage calculation. The "after" version refactors this logic using the window function sum(amount) over (). The text notes that the refactored version is more modular and readable
which are key aspects of optimization in a dbt project. This provides a concrete example of a window function replacing a subquery.
3. Stanford University
CS 145 Introduction to Databases
Lecture Notes on "Advanced SQL": University courseware on databases frequently covers the benefits of window functions. For instance
lecture notes often contrast the performance and readability of a query using RANK() OVER (...) with an equivalent query using a correlated subquery or a self-join. The materials explain that the database optimizer can often process the single scan required for a window function more efficiently than the multiple scans or complex logic required for the older constructs. (Note: Specific slide/page numbers vary by semester
but this is a standard topic in advanced SQL sections of university database courses).