Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The recursive CTE must start with the initial value 1, so we select 1 as n.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication instead of addition.
Forgetting to limit the recursion with a WHERE clause.
✗ Incorrect
The recursive step adds 1 to the previous number to generate the next number in the series.
3fill in blank
hardFix 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'
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'.
✗ Incorrect
The CTE defines a column named 'n', so we select 'n' to get the series values.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at the wrong number.
Using subtraction instead of addition.
Not incrementing the number.
✗ Incorrect
The series starts at 10 and increments by 1 until 15.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Starting at 1 instead of 2.
Adding 1 instead of 2.
Using multiplication or subtraction.
✗ Incorrect
The series starts at 2 and adds 2 each time to get even numbers up to 10.