Oracle Database Sql Certified Associate · Free Practice Question Medium

Question 9

View and examine the following available responses.

Identify the true statements regarding group functions. (Choose four.)

  • A

    They can be passed as an argument to another group function.

  • B

    They can be used with a SQL statement that has the GROUP BY clause.

  • C

    They can be used on only one column in the SELECT clause of a SQL statement.

  • D

    They can be used along with the single-row function in the SELECT clause of a SQL statement.

  • E

    They can be used on columns or expressions.

Reveal correct answers

Correct answers: A, B, D, E

Explanation

Let's examine each statement about group functions (also called aggregate functions) like SUM, AVG, MAX, MIN, COUNT, etc., and determine which are true.

True Statements:

1. They can be used on columns or expressions.

  • True.
    Group functions can operate on:

    • Columns: SUM(salary)

    • Expressions: SUM(salary + bonus)

2. They can be passed as an argument to another group function.

  • True.
    This is known as a nested group function (though rarely used).
    Example:

    (Here, AVG(salary) is grouped by department, then MAX is applied to those averages.)

3. They can be used with a SQL statement that has the GROUP BY clause.

  • True.
    In fact, group functions are commonly used with GROUP BY to get aggregated results per group.
    Example:

4. They can be used along with the single-row function in the SELECT clause of a SQL statement.

  • True.
    Single-row functions and group functions can be used together in the SELECT clause.
    Example:

False Statement:

They can be used on only one column in the SELECT clause of a SQL statement.

  • False.
    You can use multiple group functions in the same SELECT clause:


Oracle group operations. The features include aggregate functions, the GROUP BY clause, the HAVING clause, and the extensions to the GROUP BY clause—ROLLUP, CUBE, and GROUPING SETS.

Aggregate Functions

An aggregate function summarizes the results of an expression over a number of rows, returning a single value.

√  They can be used on columns or expressions.


Syntax


Parameters or Arguments

aggregate_function - name of the function—e.g., SUM, COUNT, AVG, MAX, MIN

DISTINCT - Specifies that the aggregate function should consider only distinct values of the argument expression.

ALL - Specifies that the aggregate function should consider all values, including all duplicate values, of the argument expression. The default is ALL.

expression - Specifies a column, or any other expression, on which you want to perform the aggregation.


NULLs and Aggregate Functions

All aggregate functions ignore NULLs other than COUNT(*) and GROUP BY.  For example, COUNT(column_name) ignores NULLs, whereas COUNT(*) doesn’t. The reason COUNT(*) doesn’t ignore NULLs is because it counts rows, not column values. The concept of NULL doesn’t apply to a row as a whole.  SUM, MAX, MIN, AVG, etc., all ignore NULLs.

Use of DISTINCT and ALL

Most aggregate functions allow the use of DISTINCT or ALL along with the expression argument. DISTINCT allows you to disregard duplicate expression values, while ALL causes duplicate expression values to be included in the result.

The aggregate functions that take more than one argument as input don’t allow the use of DISTINCT. These include CORR, COVAR_POP, COVAR_SAMP, and all the linear regression functions.

Functions that take only one argument as input don’t allow the use of DISTINCT. This category includes STTDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP, and GROUPING.


The GROUP BY Clause

The GROUP BY clause, along with the aggregate functions, groups a result set into multiple groups, and then produces a single row of summary information for each group.

• Generally speaking, any nonaggregate expression in your SELECT clause must also be reflected in your GROUP BY clause.

• Aggregate expressions generally require a GROUP BY clause.

• GROUP BY clause must include all nonaggregate expressions

• Aggregate functions not allowed in GROUP BY clause.

• Constants can be omitted from the GROUP BY clause.

√ They can be passed as an argument to another group function.

√ They can be used with a SQL statement that has the GROUP BY clause.

Single-row function in the SELECT clause

Examples of proper usage.


Examples of improper usage which will render an error.


√  They can be used along with the single-row function in the SELECT clause of a SQL statement.

A. Group functions can be nested within each other as arguments in SQL queries. This allows for more complex calculations and aggregations to be performed on grouped data.

B. Group functions are commonly used in conjunction with the GROUP BY clause in SQL queries. This allows for data to be grouped based on specified criteria, and group functions to be applied to each group.

C. Group functions are not limited to operating on only one column in the SELECT clause of a SQL statement. They can be applied to multiple columns or expressions to perform calculations and aggregations.

D. Group functions can be combined with single-row functions in the SELECT clause of a SQL statement. This allows for both row-level and group-level calculations to be performed in the same query.

E. Group functions can be applied to columns or expressions in SQL queries. They perform operations on a set of rows and return a single result for the entire set.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need