More Grouping Flashcards
What aggregate function counts all rows?
COUNT (*)
Last Revised: 4/2/21, 2.
What aggregate function counts all non-NULL values?
COUNT (column_name)
Last Revised: 4/2/21, 2.
What aggregate function averages all non-NULL values?
AVG (column_name)
Last Revised: 4/2/21, 2.
What aggregate function returns the maximum (highest) value?
MAX (column_name)
Last Revised: 4/2/21, 2.
What aggregate function returns the minimum (lowest) value?
MIN (column_name)
Last Revised: 4/2/21, 2.
What aggregate function returns the sum (total) of all non-NULL values?
SUM (column_name)
Last Revised: 4/2/21, 2.
What do aggregate functions do with NULL values?
Aggregate functions ignore NULL values.
Last Revised: 4/2/21, 2.5
What keyword can be used immediately after the SELECT keyword to indicate that you only want rows returned that have unique combinations of values in the column identified in the SELECT clause?
Use the keyword DISTINCT when you want unique values rather than all values.
(Last Revised: 4/2/21, 2.8)
The training companion lists two ways the use DISTINCT. What are they?
- Using DISTINCT in the SELECT clause to return rows that have unique combinations of values in the column identified in the SELECT clause
- Using DISTINCT with COUNT to return the number of unique values in the given column
(Last Revised: 4/2/21, 2. )
Can aggregate data be filtered on in the WHERE clause?
No
• Filter on aggregate data in the HAVING clause.
(Last Revised: 4/2/21, 2.10)
Can the HAVING clause reference column aliases?
No
• The HAVING clause is processed before the SELECT clause.
(Last Revised: 4/2/21, 2.10)
Is the HAVING clause processed before or after the WHERE clause?
Why is that relevant?
After
• The HAVING clause will work off of the data set the WHERE clause defined.
(Last Revised: 4/2/21, 2.10)
Which clause can be used to conditionally include/exclude groups from a query result?
The HAVING clause.
Last Revised: 4/2/21, 2.11
How would you achieve the necessary granularity before the GROUP BY clause is processed?
By using joins in the FROM clause and the WHERE clause to filter out undesired data.
(Last Revised: 4/2/21)
How would you achieve the necessary granularity after the GROUP BY clause is processed?
By using the HAVING clause.
Last Revised: 4/2/21, 2.