Which aggregate function returns the sum of values in a numeric column, excluding NULLs?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

Which aggregate function returns the sum of values in a numeric column, excluding NULLs?

Explanation:
When you aggregate numeric data in SQL, NULLs are ignored by most aggregate functions. The function that adds up all non-null numbers to produce a total is SUM, so it returns the sum of the values while skipping any NULLs. This is why it’s the right choice for getting a total. Other aggregates perform different operations: AVG computes the average of the non-null values, while MAX and MIN return the highest and lowest non-null values, respectively. For example, with values 1, 2, NULL, 3, the sum is 6, the average is 2, the maximum is 3, and the minimum is 1.

When you aggregate numeric data in SQL, NULLs are ignored by most aggregate functions. The function that adds up all non-null numbers to produce a total is SUM, so it returns the sum of the values while skipping any NULLs. This is why it’s the right choice for getting a total. Other aggregates perform different operations: AVG computes the average of the non-null values, while MAX and MIN return the highest and lowest non-null values, respectively. For example, with values 1, 2, NULL, 3, the sum is 6, the average is 2, the maximum is 3, and the minimum is 1.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy