Back to Practice
#0351
Recursive CTE Countdown
HardSQL35 min25 XP
Problem
Return n values from 3 down to 1 using a recursive CTE.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
No input tables
Examples
Example 1
Inputstart from 3
Output3, 2, 1
The recursive part keeps subtracting 1 until n is 1.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputstart from 3
Expected[[3],[2],[1]]
The recursive part keeps subtracting 1 until n is 1.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks