0
0
SQLquery~10 mins

Recursive CTE for series generation in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to start the recursive CTE with the initial value 1.

SQL
WITH RECURSIVE numbers AS (SELECT [1] AS n
Drag options to blanks, or click blank then click option'
A1
B0
Cn
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of 1 as the starting value.
Using a column name instead of a constant.
Leaving the value NULL.
2fill in blank
medium

Complete the recursive part to add 1 to the previous number.

SQL
UNION ALL SELECT n [1] 1 FROM numbers WHERE n < 5)
Drag options to blanks, or click blank then click option'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to limit the recursion with a WHERE clause.
3fill in blank
hard

Fix the error in the final SELECT to get all numbers from the CTE.

SQL
SELECT [1] FROM numbers;
Drag options to blanks, or click blank then click option'
A*
Bn
Cnumbers
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting '*' returns all columns but here only 'n' is defined.
Selecting the CTE name instead of the column.
Using an undefined column like 'count'.
4fill in blank
hard

Fill both blanks to generate numbers from 10 to 15 using a recursive CTE.

SQL
WITH RECURSIVE seq AS (SELECT [1] AS num UNION ALL SELECT num [2] 1 FROM seq WHERE num < 15) SELECT num FROM seq;
Drag options to blanks, or click blank then click option'
A10
B+
C-
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at the wrong number.
Using subtraction instead of addition.
Not incrementing the number.
5fill in blank
hard

Fill all three blanks to create a recursive CTE that generates even numbers from 2 to 10.

SQL
WITH RECURSIVE evens AS (SELECT [1] AS val UNION ALL SELECT val [2] [3] FROM evens WHERE val < 10) SELECT val FROM evens;
Drag options to blanks, or click blank then click option'
A2
B+
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 instead of 2.
Adding 1 instead of 2.
Using multiplication or subtraction.