Introduction

The HackerRank challenge "Weather Observation Station 1" is a beginner-friendly SQL problem that helps reinforce your understanding of selecting specific columns from a database table using the SELECT statement.

Problem Statement

You're provided with a table named STATION that contains various attributes about weather observation stations. Your task is to write a query that outputs only the CITY and STATE columns for all records.

Table Schema:

  • ID: Unique station identifier
  • CITY: Name of the city
  • STATE: Name of the state
  • LAT_N: Northern latitude
  • LONG_W: Western longitude

Solution

To solve this problem, you simply use the SELECT statement to retrieve only the desired columns from the table.

SQL Query:


SELECT CITY, STATE
FROM STATION;

Explanation:

  • SELECT CITY, STATE: This retrieves only the CITY and STATE columns.
  • FROM STATION: This specifies the table to query data from.

Example Test Cases

Test Case 1

Input Table:

ID | CITY      | STATE   | LAT_N | LONG_W
------------------------------------------
13 | Dallas    | TX      |  30   |   90
23 | Phoenix   | AZ      |  31   |   91
17 | Boston    | MA      |  32   |   88

Expected Output:


Dallas    TX
Phoenix   AZ
Boston    MA

Complexity Analysis

The query has a time complexity of O(n) where n is the number of rows in the STATION table. Since there is no WHERE clause or filtering, the query performs a full table scan and simply returns two columns from each row.

Conclusion

"Weather Observation Station 1" is one of the easiest SQL challenges on HackerRank. It's great for practicing column selection and helps you get comfortable working with real-world database schemas. As you progress, you’ll encounter more complex queries that build on this foundational concept.

Related Problems for Practice