Option D is correct because the desired result needs one row per customer, so the query must aggregate orders by customer_name. It also needs the output column name number_of_orders, so the aggregate expression must be aliased. Databricks SQL documentation states that count “returns the number” of rows in a group, and the SELECT clause supports a column alias for an expression result. Therefore, count(order_id) AS number_of_orders with GROUP BY customer_name is the correct statement. Option B counts correctly but does not alias the output column as required. Option A does not aggregate. Option C uses invalid SQL syntax because USE customer_name is not a grouping clause. References: Databricks count aggregate function and SELECT clause documentation.
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit