Complete the code to count only the orders with status 'shipped'.
SELECT COUNT(*) FILTER (WHERE status = [1]) AS shipped_orders FROM orders;The FILTER clause counts only rows where the condition is true. Here, it counts orders with status 'shipped'.
Complete the code to sum the amount only for orders with status 'completed'.
SELECT SUM(amount) FILTER (WHERE status = [1]) AS completed_total FROM orders;The FILTER clause here sums amounts only for orders where status is 'completed'.
Fix the error in the code to count orders with status 'returned' using FILTER.
SELECT COUNT(*) FILTER [1] AS returned_orders FROM orders;The FILTER clause requires parentheses around the WHERE condition.
Fill both blanks to count orders with status 'pending' and sum amounts for 'completed' orders.
SELECT COUNT(*) FILTER (WHERE status = [1]) AS pending_count, SUM(amount) FILTER (WHERE status = [2]) AS completed_sum FROM orders;
The first FILTER counts 'pending' orders, the second sums amounts for 'completed' orders.
Fill all three blanks to count 'shipped' orders, sum 'returned' amounts, and average 'completed' amounts.
SELECT COUNT(*) FILTER (WHERE status = [1]) AS shipped_count, SUM(amount) FILTER (WHERE status = [2]) AS returned_sum, AVG(amount) FILTER (WHERE status = [3]) AS completed_avg FROM orders;
Each FILTER clause applies to the correct status: count for 'shipped', sum for 'returned', average for 'completed'.