Skip to main contentSkip to solution

Fill in the blanks for the following SQL query to retrieve the total number of orders placed by each customer:

SELECT Customer_ID, ______(OrderID) AS TotalOrders FROM Orders GROUP BY _______.

Solution

✅ Correct Option: 3

COUNT() returns the number of rows in each group, so COUNT(OrderID)\text{COUNT(OrderID)} gives the number of orders per customer. GROUP BY Customer_ID forms one group for each customer, and COUNT is applied to each group separately.

The query becomes: SELECT Customer_ID, COUNT(OrderID) AS TotalOrders FROM Orders GROUP BY Customer_ID.


SUM and AVG: these work on the numeric values of OrderID (adding or averaging the ID numbers), not on how many orders there are.

TOTAL: this is not a standard SQL aggregate function. SQLite's total() adds values like SUM and does not count rows.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question