window functions
AI, ML & GenAI interview questions tagged window functions, across every topic.
17 questions · 2 unlocked for you
Concepts behind "window functions"
The curriculum that explains the ideas these questions test.
Foundational
Window FunctionsWindow functions run calculations over a set of rows tied to the current row, without collapsing them the way GROUP BY does, so you can rank within groups, build running totals and moving averages, and compare a row against its neighbors (LAG/LEAD), all in a single pass. They anchor analytics SQL: top-N-per-group, sessionization, cohort analysis, and period-over-period. AI, ML, and GenAI interviews probe them because they are the single most-tested SQL skill and the clearest way to write analytical queries.🗄️ Data & SQL Engineering
Core
Gaps and Islands (Sessionization)Gaps-and-islands is the pattern for grouping consecutive rows into runs (islands) split by breaks (gaps), the machinery behind sessionization, streak detection, and merging contiguous ranges. The trick is to assign a group id that holds constant within a run, classically with window functions: ROW_NUMBER differences or LAG-based break flags fed into a running sum. AI, ML, and GenAI interviews probe it because sessionizing events (user sessions, activity streaks, contiguous time ranges) is a constant data task and a sharp test of window-function fluency.🗄️ Data & SQL EngineeringSign in
Core
Ranking and Top-N Per GroupTop-N-per-group is the partition-then-filter idiom: rank rows within each group using a window function, then keep the ranks you want. The choice among ROW_NUMBER, RANK, and DENSE_RANK comes down to tie handling, and getting ties wrong is the usual bug. AI, ML, and GenAI interviews probe it because it is the cleanest replacement for a clumsy self-join or correlated subquery, and the ranking-family distinction is a quick fluency check.🗄️ Data & SQL EngineeringSign in
