SQL Questions and Answers – SQL Avg & Sum Functions

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Avg & Sum Functions”.

1. Which function returns the average value of a numeric expression?
a) Average( )
b) Avg( )
c) Ave( )
d) Average Num( )
View Answer

Answer: b
Explanation: Avg( ) function is used to calculate the average value of a specified numeric expression. This expression can be a column name or an arithmetic expression.

2. Which of the following function returns the total sum of a numeric column?
a) Add( )
b) Addition( )
c) Sum( )
d) Total sum( )
View Answer

Answer: c
Explanation: Sum is an aggregate function. This function calculates and returns the total sum of a specified numeric column.

3. If one or more columns are there in a SELECT statement in addition to the SUM or AVG function, these columns need to be a part of _______
a) Having clause
b) Group By clause
c) Order By clause
d) Where clause
View Answer

Answer: b
Explanation: It is possible to have one or more columns in addition to the SUM or AVG function in the SELECT statement. In those cases, these columns need to be part of the GROUP BY clause as well.
advertisement
advertisement

4. Arithmetic operations cannot be used inside SUM function.
a) True
b) False
View Answer

Answer: b
Explanation: The SUM function can be used to calculate the total for an expression. This expression can be a column name or an arithmetic expression. An arithmetic operation can include more than one column, such as (column1 – column2).

5. Which of the following is a correct syntax for sum( ) function?
a) Select SUM( ) from table_name;
b) Select SUM(expression) from table_name;
c) Select SUM ( ) expression from table_name;
d) Select expression SUM( ) from table_name;
View Answer

Answer: b
Explanation: The SQL SUM function is used to return the sum of an expression in a SELECT statement. Syntax for SUM function in SQL is:

SELECT SUM(expression) FROM TABLE_NAME;

6. Which of the following cannot be used as an argument for SUM function? ( Column1 and column2 are numeric fields of a table)
a) Column1*4
b) *
c) Column1 + Column2
d) Column1
View Answer

Answer: b
Explanation: Column names or arithmetic expressions can be used as arguments for SUM( ) function, whereas *,all cannot be used. This is because the SUM( ) function calculates the sum of any specified column, not the entire records.
advertisement

7. What is the syntax for basic SQL AVG function?
a) Select AVG(expression) from table;
b) Select Average(expression) from table;
c) Select AVG( ) expression from table;
d) Select expression AVG( ) from table;
View Answer

Answer: a
Explanation: The AVG function in SQL is used to return the average of an expression in a SELECT statement. The syntax for the AVG function in SQL is:

SELECT AVG(expression) FROM TABLE;

8. How many arguments does AVG and SUM have?
a) Only one
b) Specified by user
c) Two
d) Three
View Answer

Answer: a
Explanation: SUM and AVG are aggregate functions which calculate sum and average of specified numeric field columns. They have only one argument.
advertisement

9. AVG and SUM functions returns average and sum of numeric fields only.
a) True
b) False
View Answer

Answer: a
Explanation: AVG and SUM functions returns average and sum respectively of numeric fields only. If character fields are passed as arguments for those functions, query displays error.

10. AVG and SUM can be used with which of the following clause(s)?
a) Select, Group By
b) Order By, Group By
c) Having, Order By
d) Update, Having
View Answer

Answer: a
Explanation: AVG and SUM functions can be used with select, Group by, having and distinct clauses. Order By cannot be used with these functions.

Sanfoundry Global Education & Learning Series – SQL.

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.