Multiple Choice Questions - SQL GROUP BY / HAVING


Multiple Choice Questions - SQL GROUP BY / HAVING


1)
The GROUP BY statement is used in conjunction with the ............... to group the result-set by one or more columns.

A) Wildcards
B) Aggregate functions
C) Date functions
D) Joins

2)
We can also use the GROUP BY statement on more than one column.

A) True
B) False

3)
Orders table:
O_Id OrderDate OrderPrice Customer
1 2009/12/12 1000 Harry
2 2008/03/23 1600 Nancy
3 2008/09/02 700 Harry
4 2008/09/03 300 Harry
5 2008/08/30 2000 Jensen
6 2008/03/04 100 Nancy

We want to find the total sum (total order) of each customer. Which of the below statement should we use:

A) SELECT Customer,SUM(OrderPrice) FROM Order
GROUP BY Customer

B) SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Orders

C) SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY Customer

D) SELECT Customer,SUM(OrderPrice) FROM Orders
GROUP BY OrderPrice

4)
The HAVING clause is added to SQL because the WHERE keyword cannot be used with aggregate functions.

A) True
B) False

5)
A Group By clause can use column aliasing.

A) True
B) False

6)
Where filters data before grouping and Having filters data after grouping

A) True
B) False

7)
An SQL statement with the Having clause may or may not include the ............ clause

A) Group By
B) Select
C) From
D) All of above

8)
Similar to the WHERE clause, the HAVING clause requires that the column names that appear in the clause must also appear as column names in the GROUP BY clause.

A) True
B) False

9)
A HAVING clause can contain up to .......... expressions linked by logical operators such as AND and OR

A) 10
B) 20
C) 30
D) 40

10)
Null values in GROUP BY fields are omitted.

A) True
B) False

Answers