Complete the code to create a materialized view named 'sales_summary' that selects all columns from the 'sales' table.
CREATE [1] MATERIALIZED VIEW sales_summary AS SELECT * FROM sales;The keyword MATERIALIZED is required to create a materialized view in PostgreSQL.
Complete the code to refresh the materialized view named 'sales_summary'.
REFRESH [1] sales_summary;To refresh a materialized view, use REFRESH MATERIALIZED VIEW followed by the view name.
Fix the error in the code to create a materialized view that selects the total sales per product from the 'sales' table.
CREATE MATERIALIZED VIEW total_sales AS SELECT product_id, SUM(amount) [1] sales GROUP BY product_id;The FROM keyword is required to specify the source table in a SELECT statement.
Fill both blanks to create a materialized view named 'top_customers' that selects customer_id and total spent from 'orders' where total spent is greater than 1000.
CREATE MATERIALIZED VIEW top_customers AS SELECT customer_id, SUM(amount) [1] orders GROUP BY customer_id [2] SUM(amount) > 1000;
The FROM keyword specifies the table, and HAVING filters groups after aggregation.
Fill all three blanks to create a materialized view named 'recent_orders' that selects order_id, customer_id, and order_date from 'orders' where order_date is within the last 30 days.
CREATE MATERIALIZED VIEW recent_orders AS SELECT [1], [2], [3] FROM orders WHERE order_date >= CURRENT_DATE - INTERVAL '30 days';
The selected columns are order_id, customer_id, and order_date to show recent orders.