SQL & DB/HackerRank SQL Problem

[HackerRank SQL] Weather Observation Station 3, 4(MySQL)

YSY^ 2021. 2. 27. 17:35

www.hackerrank.com/challenges/weather-observation-station-3/problem

 

Weather Observation Station 3 | HackerRank

Query a list of unique CITY names with even ID numbers.

www.hackerrank.com

 

Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.
The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.'


Answer

select distinct city
from station
where (id % 2) = 0;

 


www.hackerrank.com/challenges/weather-observation-station-4/problem

 

Weather Observation Station 4 | HackerRank

Find the number of duplicate CITY names in STATION.

www.hackerrank.com

 

Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.

For example, if there are three records in the table with CITY values 'New York', 'New York', 'Bengalaru', there are 2 different city names: 'New York' and 'Bengalaru'. The query returns 1


select count(*) - count(distinct city)
from station;
728x90
반응형