1. PostgreSQL 16 Documentation
Section 7.2.4. Grouping and Window Functions: "When GROUP BY is present
or if any aggregate functions are present
it is not valid for the SELECT list expressions to refer to ungrouped columns except within aggregate functions or when the ungrouped column is functionally dependent on the grouped columns
since there would otherwise be more than one possible value to return for an ungrouped column." This rule directly invalidates options A
B
and D
while confirming C is correct.
2. Stanford University
CS 145
Introduction to Databases
Lecture Notes on SQL Aggregation: The notes state the fundamental rule of SQL aggregation: "Attributes in SELECT list that are not aggregated must be in GROUP BY list." This principle is the basis for why option C is the only valid query among the choices.
3. MIT OpenCourseWare
6.830/6.814: Database Systems
Fall 2018
Lecture 2 Notes
Section 3.2 Aggregation: "The GROUP BY clause partitions the set of tuples into groups. The aggregate is then applied to each group... Any attribute that is not aggregated in the SELECT clause must appear in the GROUP BY clause." This academic source reinforces the standard SQL syntax and logic used in the correct answer.