Complete the code to create a simple view named 'active_users' that shows users with status 'active'.
CREATE VIEW active_users AS SELECT * FROM users WHERE status = '[1]';
The view filters users with status 'active'. Using 'active' in the WHERE clause ensures only active users appear.
Complete the code to select from a view named 'sales_summary' only the rows where total_sales is greater than 1000.
SELECT * FROM sales_summary WHERE total_sales [1] 1000;
The condition 'total_sales > 1000' filters rows with sales greater than 1000.
Fix the error in the view creation by completing the code to avoid using a non-deterministic function in the view.
CREATE VIEW current_time_view AS SELECT [1] AS now_time;Views cannot use non-deterministic functions like NOW() or RAND(). CURRENT_DATE is deterministic for the day and allowed.
Fill both blanks to create a view that selects user_id and the count of orders, grouping by user_id.
CREATE VIEW user_order_counts AS SELECT user_id, COUNT([1]) AS order_count FROM orders GROUP BY [2];
Counting order_id counts orders per user. Grouping by user_id groups orders by each user.
Fill all three blanks to create a view that shows product names, total quantity sold, and only includes products with total quantity greater than 50.
CREATE VIEW popular_products AS SELECT [1], SUM([2]) AS total_sold FROM sales GROUP BY [3] HAVING total_sold > 50;
The view selects product_name, sums quantity sold, groups by product_name, and filters to products with more than 50 sold.