In SQL, which option lists only aggregate functions and correctly represents their usage on groups of rows?

Difficulty: Easy

Correct Answer: SUM, AVG, MIN, MAX, COUNT

Explanation:


Introduction / Context:
This question checks your familiarity with aggregate functions in SQL, which are used to perform calculations on groups of rows. Aggregate functions are a key part of reporting and analytics because they allow you to compute totals, averages, minimum and maximum values, and row counts. Understanding which functions are aggregate is essential when writing GROUP BY queries.


Given Data / Assumptions:

    - The context is standard SQL as implemented by Oracle and other relational databases.
    - Aggregate functions operate on sets of rows and return a single value per group.
    - Only one option lists functions that are all aggregates.


Concept / Approach:
Aggregate functions in SQL include SUM for totals, AVG for averages, MIN for minimum values, MAX for maximum values, and COUNT for counting rows or non null values. These functions are typically used in the SELECT list together with GROUP BY. Other functions such as UPPER, LOWER, and TO_CHAR are scalar functions, which operate on one row at a time. Predicates like LIKE or IN are not functions at all but conditional operators.


Step-by-Step Solution:
Step 1: Recall the standard list of aggregate functions: SUM, AVG, MIN, MAX, COUNT. Step 2: Read option A and see that it matches this standard list exactly. Step 3: Inspect option B, which lists UPPER, LOWER, INITCAP, and LENGTH, all of which are scalar string functions applied row by row. Step 4: Look at option C, which lists TO_DATE, TO_CHAR, and NVL, which are conversion and null handling functions, not aggregates. Step 5: Option D lists LIKE, IN, BETWEEN, and EXISTS, which are logical predicates for filtering rows and not functions returning numeric or scalar aggregates.


Verification / Alternative check:
A quick check is to think about which functions are allowed in a SELECT clause that uses GROUP BY without appearing in the GROUP BY list. Aggregate functions can appear in the SELECT list while other columns must appear in GROUP BY. If you try to use UPPER or TO_CHAR without grouping properly, the database will treat them as scalar functions and may require them to appear in GROUP BY as well. This confirms that only the functions in option A behave as aggregates.


Why Other Options Are Wrong:
Option B is wrong because those functions transform text on a per row basis. Option C is incorrect because it lists conversion and null handling functions that do not summarize groups of rows. Option D is wrong because it contains logical conditions rather than functions. None of these options calculate summaries such as total or average for a group of records.


Common Pitfalls:
Learners sometimes confuse scalar functions and aggregate functions, especially when mixing them in complex SELECT clauses. Another mistake is to forget to include GROUP BY when using aggregates along with regular columns, leading to SQL errors. Understanding the role of each function type helps in writing correct and efficient analytical queries.


Final Answer:
The aggregate functions in SQL are SUM, AVG, MIN, MAX, and COUNT, which are correctly grouped together in the given option.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion