Aggregate Functions Flashcards

1
Q

What are Aggregates?

A

Calculations performed on multiple rows of a Table.

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

Which function is the fastest way to calculate how many rows are in a table?

A

COUNT( )

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

What does this statement do?

SELECT COUNT(*)
FROM _______;

A

Counts every row

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

Which function makes it easy to add all values in a particular column?

A

SUM( )

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

What does this statement do?

SELECT SUM(downloads)
FROM ______;

A

This adds all values in the downloads column

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

What does the SUM( ) function do?

A

It takes the name of a column as an argument and returns the sum of all the values in that column.

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

Where are arguments passed in the functions?

A

Inside the parentheses of the function.

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

Which function returns the highest values in a column?

A

MAX( )

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

Which function returns the lowest values in a column?

A

MIN( )

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

What do all functions have in common?

A

They take the name of a column as an argument and return the value for the specified information in that column.

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

Which function quickly calculates the average value of a particular column?

A

AVG( )

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

What does this statement do?

SELECT AVG(downloads)
FROM fake_apps;

A

This statement returns the average number of downloads for an app in the database.

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

Which function makes the result Table easier to read?

A

ROUND( )

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

How many arguments does the ROUND( ) function take?

A

Two

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

What are the two arguments that the ROUND( ) function takes inside the parentheses?

A

A column name
An integer

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

What does the ROUND( ) function do?

A

It rounds the values in the column to the number of decimal places specified by the integer.

17
Q

What does this statement do?

SELECT ROUND(price, 0)
FROM fake_apps;

A

This passes the column price and integer 0 as arguments. SQL rounds the values in the column to 0 decimal places in the output.

18
Q

What clause is used with aggregate functions and with the SELECT statement to arrange identical data into groups?

A

GROUP BY

19
Q

Where does the GROUP BY statemenet go in a query?

A

It goes after any WHERE statements, but before ORDER BY or LIMIT.

20
Q

What does this statement do?

SELECT year,
AVG(imdb_rating)
FROM movies
GROUP BY year
ORDER BY year;

A

SELECT year column to get the average imdb_rating of particular years FROM the movies Table

21
Q

Unlike GROUP BY I, GROUP BY II uses ?

A

Column references

22
Q

What are the column references in GROUP BY?

A

1 is the first column selected
2 is the second column selected
3 is the third column selected

23
Q

What does this GROUP BY II do?

SELECT ROUND(imdb_rating)
COUNT(name)
FROM movies
GROUP BY 1
ORDER BY 1;

A

The 1 refers to the first column in our SELECT statement, ROUND(imdb_rating)

24
Q

Why would GROUP BY II be used?

A

To GROUP BY a calculation done on a column.

25
Q

What clause allows the filtering of groups?

A

HAVING

26
Q

True or False: HAVING allows you to filter which groups to include and which to exclude?

A

True

27
Q

What is the difference between WHERE and HAVING?

A

WHERE filters the rows while HAVING filters the groups.

28
Q

What types of WHERE clauses can be used with HAVING?

A

ALL of them

29
Q

What does this statement do?

SELECT year,
genre,
COUNT(name)
FROM movies
GROUP BY 1, 2
HAVING COUNT(name) > 10;

A

This selects the year and genre column while counting the name column from the movies Table and grouping them by column 1 and column 2. The groups will then be filtered by the HAVING that counts the name column and sets a condition to see if its greater than 10.

30
Q

What clause is used to limit the results of a query based on values of the individual rows?

A

WHERE

31
Q

What clause is used to limit the results of a query based on an aggregate property?

A

HAVING

32
Q

Where does a HAVING statement go in a query?

A

Always after GROUP BY but before ORDER BY and LIMIT.

33
Q

What are aggregate functions?

A

Combine multiple rows together to form a single value of more meaningful information.