Complete the code to start a Common Table Expression (CTE) in PostgreSQL.
WITH [1] AS (SELECT * FROM employees)The keyword WITH starts a CTE, and the name after it (like cte) defines the CTE's name.
Complete the code to select from a CTE named 'cte' in PostgreSQL.
WITH cte AS (SELECT id, name FROM employees) SELECT [1] FROM cte;After defining the CTE, you select columns from it. Here, id, name are the columns to select.
Fix the error in the CTE usage by completing the missing keyword.
WITH cte (id, name) [1] (SELECT id, name FROM employees) SELECT * FROM cte;The keyword AS is required to define the CTE's query after its name and optional column list.
Fill both blanks to create a recursive CTE that counts down from 3 to 1.
WITH RECURSIVE countdown([1]) AS (SELECT 3 UNION ALL SELECT [2] - 1 FROM countdown WHERE [2] > 1) SELECT * FROM countdown;
The recursive CTE uses the column name n and refers to it in the recursive SELECT.
Fill all three blanks to create a CTE that filters employees with salary over 50000 and selects their names and salaries.
WITH high_salary AS (SELECT [1], [2] FROM employees WHERE [3] > 50000) SELECT * FROM high_salary;
The CTE selects name and salary columns, filtering where salary is greater than 50000.