Complete the code to count the number of orders with status 'shipped'.
SELECT COUNT(CASE WHEN status = [1] THEN 1 END) AS shipped_count FROM orders;
The status value must be a string literal, so it needs to be enclosed in single quotes.
Complete the code to sum the total amount for orders with status 'completed'.
SELECT SUM(CASE WHEN status = [1] THEN amount ELSE 0 END) AS total_completed FROM orders;
We want to sum amounts only for orders where status is 'completed', so use 'completed' with quotes.
Fix the error in the code to count orders with status 'pending'.
SELECT COUNT(CASE WHEN status = [1] THEN 1 END) AS pending_count FROM orders;
String literals in SQL must be enclosed in single quotes, so use 'pending'.
Fill both blanks to calculate the count of 'shipped' and 'cancelled' orders separately.
SELECT COUNT(CASE WHEN status = [1] THEN 1 END) AS shipped_count, COUNT(CASE WHEN status = [2] THEN 1 END) AS cancelled_count FROM orders;
We count orders with status 'shipped' and 'cancelled', so use those exact string literals.
Fill all three blanks to sum amounts for 'completed' orders, count 'pending' orders, and count 'cancelled' orders.
SELECT SUM(CASE WHEN status = [1] THEN amount ELSE 0 END) AS total_completed, COUNT(CASE WHEN status = [2] THEN 1 END) AS pending_count, COUNT(CASE WHEN status = [3] THEN 1 END) AS cancelled_count FROM orders;
We sum amounts for 'completed' orders, count 'pending' orders, and count 'cancelled' orders, so use those exact string literals.