Week 3 Flashcards

(20 cards)

1
Q

What are the five basic aggregate operations in SQL?

A

COUNT, SUM, MIN, MAX, and AVG

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

What does COUNT do?

A

counts how many rows are in a particular column

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

What does SUM do?

A

adds together all the values in a particular column

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

What does MIN do?

A

returns the lowest value in a particular column

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

What does MAX do?

A

returns the highest value in a particular column

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

What does AVG do?

A

calculates the average of a group of selected values

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

Except for count, what do all these aggregations apply to?

A

a single attribute

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

What happens to NULL in aggregations?

A

it is ignored

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

What do we do if we need multiple aggregates?

A

we do one aggregate per column in a list after SELECT

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

What do we do if we want to subtract/add aggregates?

A

we can do an aggregate for each column then subtract or add in the SELECT statement.

ex: sum(revenue) - sum(budget) AS TotalProft

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

What is another way to write sum(revenue) - sum(budget) AS TotalProft?

A

Sum(revenue-budget) AS TotalProfit

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

What does everything in SELECT have to be?

A

GROUP-BY or an aggregate

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

In SQL, how does ORDER BY work?

A

it sorts in ascending order by default unless you explicitly specify DESC

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

How is the WHERE condition applied?

A

to individual rows

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

What is not allowed in the WHERE condition?

A

no aggregates are allowed here

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

What can happen when we apply the WHERE condition occasionally?

A

some groups become empty and are removed

17
Q

How is the HAVING condition applied?

A

to the entire group

18
Q

What happens to the entire group when we use HAVING?

A

either the entire group is returned or it is removed

19
Q

What can we use on the group when we use HAVING?

A

may use aggregate functions

20
Q

If a query has WHERE, GROUP BY, and HAVING, in what order does it the query?

A

begins with FROM and WHERE, then GROUP BY, then HAVING, and ends with SELECT