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
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
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
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.
4. Arithmetic operations cannot be used inside SUM function.
a) True
b) False
View Answer
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
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
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.
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
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
Explanation: SUM and AVG are aggregate functions which calculate sum and average of specified numeric field columns. They have only one argument.
9. AVG and SUM functions returns average and sum of numeric fields only.
a) True
b) False
View Answer
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
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.