DEV Community

Cover image for HackerRank SQL Preparation: Weather Observation Station 3(MySQL)
Christian Paez
Christian Paez

Posted on

2

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 CITY FROM STATION WHERE ID % 2 = 0;
Enter fullscreen mode Exit fullscreen mode

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.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more