SQL Window Functions and CTEs in DuckDB: Two Mistakes
Learn CTEs and window functions with DuckDB on a tiny orders table, then see two common mistakes, with real output.
Video #07 ยท SQL and analytics
Steps in the video
Files
- bad_where.sql (4 lines)
- cte.sql (9 lines)
- qualify.sql (4 lines)
- run.py (11 lines)
- setup.sql (11 lines)
- ties.sql (9 lines)
- window.sql (9 lines)
Tested with
Python 3.12.15 | duckdb==2.0.0
What this does not show
A made-up table of eight orders in DuckDB 2.0.0; nothing here measures speed. QUALIFY is not standard SQL, and other databases can differ in syntax and in how window frames treat ties.
Sources
Learning IT by Example.