Difficulty: Easy
Correct Answer: Invalid (MIN and MAX also work with dates/times and text; SUM/AVG require numeric)
Explanation:
Introduction / Context:
SQL provides aggregate functions such as SUM, AVG, MIN, and MAX. Understanding which data types each function supports is essential for writing correct queries. The statement claims all four can be used only with numeric columns; this is partially true for two of them and false for the others.
Given Data / Assumptions:
Concept / Approach:
SUM and AVG require numeric (or numeric-coercible) data to perform arithmetic. In contrast, MIN and MAX operate over any comparable domain, including dates/times (earliest/latest) and text (lexicographic order). Therefore, the blanket restriction “only numeric” is incorrect.
Step-by-Step Solution:
Verification / Alternative check:
Run examples: SELECT MIN(last_name), MAX(last_name) FROM employees; and SELECT MIN(order_date), MAX(order_date) FROM orders; which return non-numeric results. Conversely, SUM/AVG on text will error unless cast to numeric.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming MIN/MAX imply numeric; overlooking collation effects on text ordering; forgetting to cast string-encoded numbers before SUM/AVG.
Final Answer:
Invalid (MIN and MAX also work with dates/times and text; SUM/AVG require numeric)
Discussion & Comments