We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 4
You are viewing a single comment's thread. Return to all 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.