RDBMS Questions and Answers – Aggregate Functions

This set of RDBMS Multiple Choice Questions & Answers (MCQs) focuses on “Aggregate Functions”.

1. Which of the following is not a built in aggregate function in SQL?
a) avg
b) max
c) total
d) count
View Answer

Answer: c
Explanation: SQL does not include total as a built in aggregate function. The avg is used to find average, max is used to find the maximum and the count is used to count the number of values.

2. Observe the given SQL query and choose the correct option.

SELECT branch_name, COUNT (DISTINCT customer_name) 
FROM depositor, account 
WHERE depositor.account_number = account.account_number 
GROUP BY branch_id

a) The query is syntactically correct but gives the wrong answer
b) The query is syntactically wrong
c) The query is syntactically correct and gives the correct answer
d) The query contains one or more wrongly named clauses.
View Answer

Answer: b
Explanation: The query is syntactically wrong. The attribute in the group by clause must be one of the attributes specified in the select clause.
advertisement
advertisement

3. State true or false: SQL does not permit distinct with count(*)
a) True
b) False
View Answer

Answer: a
Explanation: SQL does not permit distinct with count(*) but the use of distinct is allowed with max and min.

4. We apply the aggregate function to a group of sets of tuples using the _______ clause.
a) group by
b) group
c) group set
d) group attribute
View Answer

Answer: a
Explanation: We apply the aggregate function to a group of sets of tuples using the group by clause. The group by clause must always be used whenever we are willing to apply the aggregate function to a group of sets of tuples.

5. Choose the correct option regarding the query

advertisement
SELECT branch_name, COUNT (DISTINCT customer_name) 
FROM depositor, account 
WHERE depositor.account_number = account.account_number 
       GROUP BY branch_id
       HAVING avg(balance) = 10000;

a) The having clause checks whether the query result is true or not
b) The having clause does not check for any condition
c) The having clause allows only those tuples that have average balance 10000
d) None of the mentioned
View Answer

Answer: c
Explanation: The having clause is used to check for conditions that need to be set on aggregate functions.

6. The _____ aggregation operation adds up all the values of the attribute
a) add
b) avg
c) max
d) sum
View Answer

Answer: d
Explanation: The sum aggregation operation adds up all the values of the specified attribute. There does not exist any aggregation such as add.
advertisement

7. State true or false: Any attribute which is present in the having clause without being aggregated must not be present in the group by clause.
a) True
b) False
View Answer

Answer: b
Explanation: Any attribute which is present in the having clause without being aggregated must be present in the group by clause. Otherwise, the query is considered to be erroneous.

8. State true or false: We can rename the resulting attribute after the aggregation function has been applied
a) True
b) False
View Answer

Answer: a
Explanation: Yes, we can rename the resulting attribute after the aggregation function has been applied by using a specific keyword.

9. Which keyword is used to rename the resulting attribute after the application of the aggregation function?
a) rename
b) as
c) replace
d) to
View Answer

Answer: b
Explanation: The “as” keyword is used to rename the resulting attribute after the aggregation function has been applied. Just like any other renaming operation, the as keyword simplifies the name of the relation.

10. What values does the count(*) function ignore?
a) Repetitive values
b) Null values
c) Characters
d) Integers
View Answer

Answer: b
Explanation: The count(*) aggregation function ignores null values while calculating the number of values in a particular attribute.

Sanfoundry Global Education & Learning Series – RDBMS.

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

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

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.