Intermediate SQL - Aggregate Functions Flashcards

SQL allows you to zoom in and out to better understand an entire dataset, its subsets, and its individual records. You'll learn to summarize data using aggregate functions and perform basic arithmetic calculations inside queries to gain insights into what makes a successful film.

1
Q

What does an aggregate function do?

A

performs calculation on several values and returns a single value

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

What are the five most common aggregate funtions?

A

1) COUNT()
2) AVG()
3) SUM()
4) MIN()
5) MAX()

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

What aggregate functions can only be used with numerical fields?

A

AVG and SUM

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

What aggregate functions can be used with various types of data?

A

COUNT, MIN, and MAX

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

Why are we able to combine aggregate functions with the WHERE clause?

A

because the WHERE clause executes before the SELECT statement

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

What are the two parameters for the ROUND() operator?

A

ROUND(number_to_round, decimal_places)

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

True/False - The decimal_places parameter in the ROUND() operator is optional if you are rounding to a whole number.

A

True - ROUND() will return a whole number by default

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

True/False - A negative number can be placed in the decimal_places parameter in the ROUND() operator.

A

True - negative numbers will round to the left of the decimal point instead of the right

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

ROUND() can only be used with what type of fields?

A

numerical fields

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

What are the four basic arithmetic symbols you can use in SQL? What do parenthesis determine?

A

+, -, *, and / (parenthesis indicates the order of execution)

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

What gets returned when we try dividing integers? Why?

A

an integer because SQL assumes we want an integer back if we divide two integers. We can add decimals to our numbers to get more precision.

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

What is the difference between aggregate functions vs. arithmetic?

A

Aggregate functions (like SUM) perform their operations on the fields vertically while arithmetic adds up the records horizontally

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

When summarizing data with aggregate functions and arithmetic we will always need to use what?

A

An alias

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

Where are aliases defined in the query?

A

SELECT statement

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

Aliases defined in the SELECT clause cannot be used in the WHERE clause due to what?

A

order of execution

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