Complete the code to create a view named 'employee_view' that shows all columns from the 'employees' table.
CREATE VIEW employee_view AS SELECT [1] FROM employees;Using * selects all columns from the table, which is common when creating a simple view.
Complete the code to select only the 'name' and 'department' columns from the 'employee_view'.
SELECT [1] FROM employee_view;To get the employee's name and department, select those two columns separated by a comma.
Fix the error in the code to create a view that shows employees with salary greater than 50000.
CREATE VIEW high_salary AS SELECT * FROM employees WHERE salary [1] 50000;
The condition should be salary greater than 50000, so use the '>' operator.
Fill both blanks to create a view named 'dept_count' that shows each department and the number of employees in it.
CREATE VIEW dept_count AS SELECT [1], COUNT(*) AS employee_count FROM employees GROUP BY [2];
Grouping by 'department' lets us count employees per department. We select 'department' to show it in the result.
Fill all three blanks to create a view 'top_earners' showing employee names, salaries, and only those earning more than 70000.
CREATE VIEW top_earners AS SELECT [1], [2] FROM employees WHERE [3] > 70000;
Select 'name' and 'salary' columns, and filter where 'salary' is greater than 70000.