← Back to CTEs
Question 44
Months One to Twelve
Months One to Twelve
Use a recursive CTE namedmonthswith a single columnnto generate the numbers 1 to 12 without reading any table: the anchor selects 1, and the recursive step adds 1 to the previous row whilenis below 12. Return one column aliasedmonth, sorted ascending.
Expected result:
+-------+ | month | +-------+ | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | +-------+ (showing 10 of 12 rows)
Hints3 available
Sign in to use hintsTopics:
CTEs
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)
Results
Run your SQL to see every statement's output here, then how it compares with the expected answer.
Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.