HackerRank SQL Preparation: Weather Observation Station 3(MySQL)

Problem Statement:
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.

Link: HackerRank – Weather Observation Station 3

Solution:

SELECT DISTINCT C…


This content originally appeared on DEV Community and was authored by Christian Paez

Problem Statement:
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.

Link: HackerRank - Weather Observation Station 3

Solution:

SELECT DISTINCT CITY FROM STATION WHERE ID % 2 = 0;

Explanation:

  • SELECT DISTINCT CITY: This part of the query specifies that you want to retrieve the CITY column from the STATION table, and DISTINCT ensures that each city name is unique, eliminating any duplicates from the result.
  • FROM STATION: Indicates that you are selecting data from the STATION table.
  • WHERE ID % 2 = 0: This condition filters the rows to include only those cities where the ID is an even number. The modulo operation (% 2 = 0) checks if the ID is divisible by 2, meaning it's even.

This query will return a list of unique city names from the STATION table where the city has an even ID number. The result will exclude any duplicate city names.


This content originally appeared on DEV Community and was authored by Christian Paez


Print Share Comment Cite Upload Translate Updates
APA

Christian Paez | Sciencx (2024-08-27T01:41:25+00:00) HackerRank SQL Preparation: Weather Observation Station 3(MySQL). Retrieved from https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/

MLA
" » HackerRank SQL Preparation: Weather Observation Station 3(MySQL)." Christian Paez | Sciencx - Tuesday August 27, 2024, https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/
HARVARD
Christian Paez | Sciencx Tuesday August 27, 2024 » HackerRank SQL Preparation: Weather Observation Station 3(MySQL)., viewed ,<https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/>
VANCOUVER
Christian Paez | Sciencx - » HackerRank SQL Preparation: Weather Observation Station 3(MySQL). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/
CHICAGO
" » HackerRank SQL Preparation: Weather Observation Station 3(MySQL)." Christian Paez | Sciencx - Accessed . https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/
IEEE
" » HackerRank SQL Preparation: Weather Observation Station 3(MySQL)." Christian Paez | Sciencx [Online]. Available: https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/. [Accessed: ]
rf:citation
» HackerRank SQL Preparation: Weather Observation Station 3(MySQL) | Christian Paez | Sciencx | https://www.scien.cx/2024/08/27/hackerrank-sql-preparation-weather-observation-station-3mysql/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.