Lecture 8 Flashcards

1
Q

SELECT & aggregation

A

SELECT statement aggregates

  • Count,
  • sum,
  • average,
  • min & max
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

aggregate functions

A
  • aggregate functions perform a calculation on a set of values, and returns a single value
    • 4+2+3+1+7=16
  • Each aggregate function operates on a single column of a table and returns a single value
  • used with the GROUP BY clause of the SELECT statement
  • except for COUNT, aggregate functions ignore null values

ISO standard defines five aggregate functions:

  • COUNT
  • SUM (numeric only)
  • AVG (numeric only)
  • MIN
  • MAX
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

COUNT(*)

A

COUNT(*) counts all rows of a table, regardless of whether nulls or duplicate values occur

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

DISTINCT

A

use DISTINCT before column name to eliminate duplicates

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

GROUP BY & aggregate functions

A

The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result set by one or more columns

SELECT column_name(s)

FROM Table_name

WHERE condition

GROUP BY column_name(s)

ORDER BY column_name(s);

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

HAVING & aggregrate functions

A

enables you to specify conditions that filter which group results appear in the results

Similar to WHERE, but WHERE filters individual rows whereas HAVING filters groups

(the HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions)

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

where can aggregate functions be used

A

Only in SELECT list and in HAVING claus

If SELECT list includes an aggregate function and there is no GROUP BY clause, SELECT list cannot reference a column out with an aggregate function

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

example use of COUNT(*)

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

Example of Having

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

JOIN

A

They are used to join two or more different tables on a point in which both the tables match the same value and property

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

inner, outer joins, etc. check the ppt

A

inner, outer joins, etc. check the ppt

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