Weather Observation Station 4

  • + 2 comments

    You want the total number of cities in the Station table, which is NUM, and you can get that with Select Count(City) from Station.

    You also want the number of distinct cities in the Station table, or the number of Cities not counting duplicates. So if you've got the following entries:

    ID | Name

    1 | Helsinki

    2 | Helsinki

    3 | Helsinki

    You still want Helsinki counted in the count, but you only want it counted a single time, which is what Distinct will do for you. This is what NUMunique is. If the city exists multiple times, you don't want to discount it outright, you just don't want to count it multiple times. You can do this with Select Count(Distinct City) from Station.

    If you combine those two queries, you get the number of duplicate cities that exist in Station, which is the same as NUM - NUMunique, which is what the question asked for.