A supermarket has a foods table with columns category and qu…
A supermarket has a foods table with columns category and quantity. The manager wants to see the total quantity for each category (e.g., Fruit, Vegetables). Which query should they run? SELECT category, SUM(quantity) FROM foods GROUP BY category SELECT SUM(quantity) FROM foods SELECT category, quantity FROM foods ORDER BY category SELECT * FROM foods GROUP BY category Answer: SELECT category, SUM(quantity) FROM foods GROUP BY category Explanation: GROUP BY organizes rows into groups based on category, and SUM(quantity) aggregates the total for each group. Using only SUM(quantity) would return one grand total, not per category. Ordering by category does not summarize values, and SELECT * … GROUP BY is invalid without aggregates.
Read Details