SQL Server Questions and Answers – Aggregation of Data

This set of SQL Server Multiple Choice Questions & Answers (MCQs) focuses on “Aggregation of Data”.

1. Aggregate functions are functions that take a ___________ as input and return a single value.
a) Collection of values
b) Single value
c) Double value
d) All of the mentioned
View Answer

Answer: a
Explanation: Aggregate functions perform a calculation on a set of values.

2. SQL applies predicates in the _______ clause after groups have been formed, so aggregate functions may be used.
a) Group by
b) With
c) Where
d) Having
View Answer

Answer: b
Explanation: The with clause provides a way of defining a temporary relation whose definition is available only to the query in which the with clause occurs.

3. The ________ keyword is used to access attributes of preceding tables or subqueries in the from clause.
a) In
b) Lateral
c) Having
d) With
View Answer

Answer: b
Explanation: Select name, salary, avg salary from instructor I1, lateral (select avg(salary) as avg salary from instructor I2 where I2.dept name= I1.dept name);
Without the lateral clause, the subquery cannot access the correlation variable I1 from the outer query.
advertisement
advertisement

4. Which of the following is not an aggregate function?
a) Avg
b) Sum
c) With
d) Min
View Answer

Answer: c
Explanation: With is used to create temporary relation and its not an aggregate function.

5. If we do want to eliminate duplicates, we use the keyword __________in the aggregate expression.
a) Distinct
b) Count
c) Avg
d) Primary key
View Answer

Answer: a
Explanation: Distinct keyword is used to select only unique items from the relation.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

6. All aggregate functions except __________ ignore null values in their input collection.
a) Count(attribute)
b) Count(*)
c) Avg
d) Sum
View Answer

Answer: a
Explanation: * is used to select all values including null.

7. A Boolean data type that can take values true, false, and ____________
a) 1
b) 0
c) Null
d) Unknown
View Answer

Answer: d
Explanation: Unknown values do not take null value but it is not known.
advertisement

8. Which of the following should be used to find all the courses taught in the Fall 2009 semester but not in the Spring 2010 semester?
a)

SELECT DISTINCT course id 
FROM SECTION
WHERE semester = ’Fall’ AND YEAR= 2009 AND 
course id NOT IN (SELECT course id FROM SECTION WHERE semester = ’Spring’ AND YEAR= 2010);

b)

advertisement
SELECT DISTINCT course_id
FROM instructor
WHERE name NOT IN (’Fall’, ’Spring’);

c)

SELECT course id
FROM SECTION
WHERE semester = 'Spring' AND YEAR= 2010);

d)

SELECT COUNT (DISTINCT ID)
FROM takes
WHERE (course id, sec id, semester, YEAR) IN (SELECT course id, sec id, semester, YEAR
FROM teaches
WHERE teaches.ID= 10101);
View Answer
Answer: a
Explanation: Aggregate function can be used inside nested subqueries.
 
 

9. The phrase “greater than at least one” is represented in SQL by ___________
a) < all
b) < some
c) > all
d) > some
View Answer

Answer: d
Explanation: > some takes at lest one value above it.

10. We can test for the nonexistence of tuples in a subquery by using the __________ construct.
a) Not exist
b) Not exists
c) Exists
d) Exist
View Answer

Answer: b
Explanation: Exists is used to check for the existence of tuples.

Sanfoundry Global Education & Learning Series – SQL Server.

To practice all areas of SQL Server, 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.