Complete the code to create a view named 'active_users' that selects all columns from the 'users' table where 'status' is 'active'.
CREATE VIEW active_users AS SELECT * FROM users WHERE status = [1];The value 'active' must be a string literal in SQL, so it needs single quotes.
Complete the code to create a view named 'recent_orders' that selects 'order_id' and 'order_date' from 'orders' where 'order_date' is after January 1, 2023.
CREATE VIEW recent_orders AS SELECT order_id, order_date FROM orders WHERE order_date > [1];In PostgreSQL, the DATE keyword before a string literal explicitly casts it as a date type, which is best practice here.
Fix the error in the code to create a view named 'customer_emails' selecting 'email' from 'customers'.
CREATE VIEW customer_emails [1] SELECT email FROM customers;The correct keyword to define the query for a view is AS.
Fill both blanks to create a view named 'top_products' selecting 'product_id' and 'sales' from 'products' where 'sales' is greater than 1000.
CREATE VIEW [1] AS SELECT product_id, sales FROM products WHERE sales [2] 1000;
The view name should be 'top_products' and the condition is sales greater than 1000, so use >.
Fill all three blanks to create a view named 'employee_summary' selecting 'employee_id', 'department', and the count of projects as 'project_count' from 'employees' joined with 'projects' on 'employee_id', grouping by 'employee_id' and 'department'.
CREATE VIEW [1] AS SELECT employee_id, department, COUNT(project_id) AS [2] FROM employees JOIN projects ON employees.employee_id = projects.[3] GROUP BY employee_id, department;
The view name is 'employee_summary', the alias for count is 'project_count', and the join is on 'employee_id'.