0% found this document useful (0 votes)
6 views

SQL CH 05

The document contains questions and answers about SQL aggregate functions and how to use them in queries. It discusses scalar vs aggregate functions and how aggregate functions can be used to summarize data by using keywords like GROUP BY, HAVING, ORDER BY, COUNT, SUM, AVG, MIN, MAX. It also covers SQL extensions for summarization like ROLLUP, CUBE, and GROUPING SETS.

Uploaded by

tarifditcr60
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

SQL CH 05

The document contains questions and answers about SQL aggregate functions and how to use them in queries. It discusses scalar vs aggregate functions and how aggregate functions can be used to summarize data by using keywords like GROUP BY, HAVING, ORDER BY, COUNT, SUM, AVG, MIN, MAX. It also covers SQL extensions for summarization like ROLLUP, CUBE, and GROUPING SETS.

Uploaded by

tarifditcr60
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Q1. Which one is a scalar function?

A. A function that operates on a single value and returns a single value


B. A function that operates on a series of values and returns a single value
C. A function that always returns the same value for a given set of arguments
D. A function that takes no parameter
Answer: A
Q2. Which one is an aggregate function?
A. A function that operates on a single value and returns a single value
B. A function that operates on a series of values and returns a single value
C. A function that always returns the same value for a given set of arguments
D. A function that takes no parameter
Answer: B
Q3. Why aggregate functions are column functions?
A. Because they can be used in column definitions in tables
B. Because they typically operate on the values in a column
C. Because they typically add extra columns in the result set
D. All of the above
Answer: B
Q4. Which queries are referred to as summary queries?
A. A query that contains one or more user-defined functions
B. A query that returns a single scalar value
C. A query that contains GROUP BY clause
D. A query that contains one or more aggregate functions
Answer: D
Q5. Which aggregate function does not always require an expression to operate on?
A. AVG
B. MAX
C. MIN
D. COUNT
Answer: D
Q6. Aggregate functions always exclude NULL values.
A. True
B. False
Answer: A
Q7. Which one returns number of rows in the base table?
A. COUNT (ALL expression)
B. COUNT (DISTINCT expression)
C. COUNT ()
D. COUNT (*)
Answer: D
Q8. On which functions ALL or DISTINCT has no effect?
A. SUM and AVG
B. SUM and COUNT
C. MIN and MAX
D. COUNT and AVG
Answer: C
Q9. Which functions accept expression that results in only a numeric value?
A. SUM and AVG
B. SUM and COUNT
C. MIN and MAX
D. COUNT and AVG
Answer: A
Q10. By default, all aggregate functions exclude duplicate values.
A. True
B. False
Answer: B
[By default, all values are included in the calculation regardless of whether they are
duplicated.
Ref. Page: 161]
Q11. If your query has non-aggregate columns with aggregate functions, what should you do
to the query to work? [There may be multiple answers]
A. Specify all non-aggregate columns in ORDER BY clause a
B. Specify all non-aggregate columns in GROUP BY clause
C. Include OVER clause with each aggregate function
D. Include COMPUTE BY clause in your query
Answer: B, C
Q12. Which query or queries will work?
A. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers
B. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers ORDER BY
Country
C. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers GROUP BY
Country
D. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers SORT BY
Country
Answer: C
Q13. Which query or queries will work?
A. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers GROUP BY
Country WHERE Country = ‘Germany’
B. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers WHERE
Country = ‘Germany’ GROUP BY Country
C. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers GROUP BY
Country HAVING Country = ‘Germany’
D. Select Country, Count(CustomerId) AS ‘No. of customers’ FROM Customers HAVING
Country = ‘Germany’ GROUP BY Country
Answer: B, C [Having Clause is used with GROUP BY and it must be after GROUP BY clause.
WHERE clause can be used but before GROUP BY]
Q14. Which query or queries will work?
A. Select City, Count(CustomerId) AS ‘No. of customers’ FROM Customers GROUP BY City
WHERE Country = ‘Germany’
B. Select City, Count(CustomerId) AS ‘No. of customers’ FROM Customers WHERE Country
= ‘Germany’ GROUP BY City
C. Select City, Count(CustomerId) AS ‘No. of customers’ FROM Customers GROUP BY
Country, City HAVING Country = ‘Germany’
D. Select City, Count(CustomerId) AS ‘No. of customers’ FROM Customers HAVING Country
= ‘Germany’ GROUP BY City
Answer: B
[Having can include columns that are in group by list. Where can you include any column.
Where clause must be before group by]
Q15. Which query is correct?
A. SELECT Country, COUNT (*) FROM Customers WHERE COUNT (*) >5 GROUP BY Country
B. SELECT Country, COUNT (*) FROM Customers GROUP BY Country HAVING COUNT (*)
>5
C. SELECT Country, COUNT (*) FROM Customers HAVING COUNT (*) >5 GROUP BY
Country
D. SELECT Country, COUNT (*) FROM Customers GROUP BY Country WHERE COUNT (*) >5
Answer: B
[If filter has aggregate it must be with HAVING Clause]
Q16. Which is not extension operator of SQL Server for summarizing data?
A. ROLLUP
B. CUBE
C. OVER
D. EXCEPT
Answer: D
[4 operators: ROLLUP, CUBE, GROUPING SETS and OVER
Ref. Page: 172]
Q17. Which of the following is not true for the ROLLUP operator?
A. It adds a summary row for each specified group
B. It adds a summary row at the end of the result set that summarizes the entire result
set
C. If you use ROLLUP, you can use DISTINCT keyword in any of the aggregate functions
used in the query
D. If you use ROLLUP, you can add ORDER BY clause in your query
Answer: C
[Ref. Page: 173]
Q17. Which operator adds summary row for every combination of groups specified?
A. ROLLUP
B. CUBE
C. GROUPING SETS
D. OVER
Answer: B
Q18. With GROUPING SETS, how can you add summary row that summarizes the entire result
set?
A. Within parentheses after the GROUPING SETS operator, add a * symbol
B. Within parentheses after the GROUPING SETS operator, add an empty set of
parentheses
C. After the GROUPING SETS operator, add an empty set of parentheses
D. You need not do anything; GROUPING SETS add a summary row by default
Answer: B

You might also like