0
0
SQLquery~10 mins

CTE referencing another CTE 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 define a CTE named 'first_cte' that selects all columns from the 'employees' table.

SQL
WITH first_cte AS (SELECT * FROM [1]) SELECT * FROM first_cte;
Drag options to blanks, or click blank then click option'
Adepartments
Bemployees
Csalaries
Dprojects
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a table other than 'employees' will cause the query to return wrong data or error.
2fill in blank
medium

Complete the code to define a second CTE named 'second_cte' that selects only the 'id' and 'name' columns from 'first_cte'.

SQL
WITH first_cte AS (SELECT * FROM employees), second_cte AS (SELECT [1] FROM first_cte) SELECT * FROM second_cte;
Drag options to blanks, or click blank then click option'
Asalary, department
Bid, salary
Cname, department
Did, name
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting columns not present in 'first_cte' will cause errors.
3fill in blank
hard

Fix the error in the code by choosing the correct keyword to reference the first CTE inside the second CTE.

SQL
WITH first_cte AS (SELECT * FROM employees), second_cte AS (SELECT id, name FROM [1]) SELECT * FROM second_cte;
Drag options to blanks, or click blank then click option'
Afirst_cte
Bdepartments
Csecond_cte
Demployees
Attempts:
3 left
💡 Hint
Common Mistakes
Referencing the base table or wrong CTE name causes errors.
4fill in blank
hard

Fill both blanks to complete the query that defines two CTEs where the second CTE filters employees with salary greater than 50000.

SQL
WITH first_cte AS (SELECT * FROM [1]), second_cte AS (SELECT id, name FROM first_cte WHERE [2] > 50000) SELECT * FROM second_cte;
Drag options to blanks, or click blank then click option'
Aemployees
Bdepartments
Csalary
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong table or column names causes errors or wrong results.
5fill in blank
hard

Fill all three blanks to complete the query that defines three CTEs: first selects employees, second filters by department 'Sales', third selects names and salaries above 60000.

SQL
WITH first_cte AS (SELECT * FROM [1]), second_cte AS (SELECT * FROM first_cte WHERE [2] = 'Sales'), third_cte AS (SELECT [3] FROM second_cte WHERE salary > 60000) SELECT * FROM third_cte;
Drag options to blanks, or click blank then click option'
Aemployees
Bdepartment
Cname, salary
Did, salary
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong column names or selecting wrong columns causes errors or wrong output.