RSS Feed

Multiple Choice Questions - SQL HAVING / GROUP BY

Multiple Choice Questions - SQL HAVING / GROUP BY

1. Having clause is processed after the GROUP BY clause and any aggregate functions.

A) True
B) False

2. In the context of MS SQL SERVER, with the exception of ............ column(s), any column can participate in the GROUP BY clause.

A) bit
B) text
C) ntext
D) image
E) All of above

3. The sequence of the columns in a GROUP BY clause has no effect in the ordering of the output.

A) True
B) False

4. You want all dates when any employee was hired. Multiple employees were hired on the same date and you want to see the date only once.

Query - 1
Select distinct hiredate
From hr.employee
Order by hiredate;
Query - 2
Select hiredate
From hr.employees 
Group by hiredate
Order by hiredate;
Which of the above query is valid?

A) Query - 1
B) Query - 2
C) Both

5. GROUP BY ALL generates all possible groups - even those that do not meet the query's search criteria.

A) True
B) False

6. All aggregate functions ignore NULLs except for ............

A) Distinct
B) Count (*)
C) Average()
D) None of above

7. Using GROUP BY ............ has the effect of removing duplicates from the data.

A) with aggregates
B) with order by
C) without order by
D) without aggregates

8. Below query is run in SQL Server 2012, is this query valid or invalid:
Select count(*) as X
from Table_Name
Group by ()
A) Valid
B) Invalid

9. For the purposes of ............, null values are considered equal to other nulls and are grouped together into a single result row.

A) Having
B) Group By
C) Both of above
D) None of above

10. If you SELECT attributes and use an aggregate function, you must GROUP BY the non-aggregate attributes.

A) True
B) False

Answers