Return to Video

After Aggregating - Intro to Relational Databases

  • 0:00 - 0:03
    Which species does
    the zoo have only one of?
  • 0:03 - 0:06
    That seems like a pretty
    straightforward question, but
  • 0:06 - 0:09
    it turns out that you
    can't answer it like this.
  • 0:09 - 0:11
    The reason is that where,
  • 0:11 - 0:17
    applies to the rows of the underlying
    table before count is performed.
  • 0:17 - 0:20
    There's no nom column
    in the animals table.
  • 0:20 - 0:22
    And you can't use where
    after a group by anyway.
  • 0:22 - 0:28
    If you tried this query out, you'd get
    a big error, but if we change just one
  • 0:28 - 0:32
    word, we can make this right,
    whereas where filters the source table,
  • 0:32 - 0:36
    animals, having filters
    the result table.
  • 0:36 - 0:39
    So having applies after
    the group BI aggregation.
  • 0:39 - 0:41
    And we'll get the right answer.
  • 0:41 - 0:43
    Again, there is another way
    of answering this question,
  • 0:43 - 0:46
    using a more complicated sort
    of query called a subselect.
  • 0:46 - 0:49
    But this is the easy way to do it.
  • 0:49 - 0:51
    So now for
    a different sort of question and a quiz.
  • 0:52 - 0:55
    Which food is eaten by only one animal?
  • 0:55 - 0:59
    Not just by one species, but only one
    individual animal in the whole zoo?
  • 0:59 - 1:03
    To answer this, you'll have to
    use both the having clause, and
  • 1:03 - 1:04
    a join that we've seen before.
Title:
After Aggregating - Intro to Relational Databases
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
ud197 - Intro to RDB
Duration:
01:05

English subtitles

Revisions Compare revisions