Working with Aggregates Flashcards

1
Q

What’s an aggregate function?

A

These are functions that perform a calculation on a set of values and return a single value. Examples include SUM, COUNT, AVG (average), MIN (minimum), and MAX (maximum).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

In databases, when you have a lot of data and you want to summarize it or get some statistics (like totals, averages, counts, etc.) for groups of related data, what would you use?

A

Aggregates and Grouping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

List everything you need to know about Aggregates and Grouping

A

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

GROUP BY comes after the WHERE clause (if there is one) and before the ORDER BY clause

Items in the SELECT statement that aren’t aggregated must be included in the GROUP BY clause

Multiple aggregate functions can be applied to a single query

Different columns can be aggregated in the same query

If you use an ORDER BY clause the column(s) must be included in the GROUP BY clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the count() function do?

A

The COUNT function counts the total occurrences of the specified column in a record set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens when you use an asterisk with the count function?

A

The function counts the total number of rows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List what you know about the SUM() function.

A

The SUM function adds together the numbers in a grouping

You insert the DISTINCT keyword if you want to only add
distinct values

SUM will add both positive and negative values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List what you know about the AVG() function

A

The AVG function returns the average of
values in a group

Null values are ignored

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List what you know about the Min() and Max() function

A

The MIN function returns the minimum value in a column

The MAX function returns the maximum
value in a column

Both functions can work on string as well as numeric values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When can you aggregate data without the GROUP BY function?

A

The GROUP BY clause is not used if you are grouping
against an entire result set or table

If there are no non-aggregated columns then you don’t need the GROUP BY clause

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

List what you know about Aggregates and NULL

A

List what you know about the aggregate functions will
exclude NULL values from their calculations

If you want to include NULL values then you will need to enclose the column in an ISNULL scalar function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

List what you

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly