Loading
Lesson 01
Courses / HackerRank SQL Problem Solving Solution Challenges
Weather Observation Station 1 | SQL Basic Select | HackerRank Solution

Summary

Weather Observation Station 1 - SQL Problem Summary

In this lesson, the instructor solves the problem of Weather Observation Station 1 from the SQL section of HackerRank. Below is a summary of the steps taken to address the problem.

Problem Overview

The task is to query the state from the station table, which is defined with the following columns:

  • ID
  • city
  • state
  • lat_n
  • long_w

For this problem, only the city and state columns are of interest. The ID, lat_n, and long_w columns can be ignored.

Querying the Data

To view the data structure, one can use the following command:

SELECT * FROM station;

This will display all the columns in the dataset.

SQL Query

To accomplish the task, the instructor executes the following SQL query:

SELECT city, state FROM station;

Important Notes

  • Be cautious when modifying the query, as incorrect changes may lead to errors.
  • Validate the query by running the code before submitting it.

Conclusion

Once the query is confirmed to be correct, the next step is to submit the code. This completes the solution for Weather Observation Station 1.

Video Transcript

In this lesson I will solve the problem of weather observation station 1 from the basic select section in the SQL Category Hacker Rank. So here is the problem, it states that we should query the setting state from the station table. Station table is defined as following, we have the columns ID, city, state, lat, underscore n, long underscore w. Actually, we don't care about ID nor lat in nor long at w for this problem, all we care about is the city column, state column, and we're going to carry those columns from the table station. If you want to get a glimpse of what the table looks like, you can simply go here and right hand side and say select star from station the table name. And click around code to see what the data looks like. As you can see here, this is what the data looks like. You have the ID, it's a number, followed by the city name, followed by the state, in this case an abbreviation, and then we have lat underscore n followed by long underscore w. So basically all we want to do here in this problem is select, we only want to show the name of the city and the state abbreviation. So for that, we simply go here and instead of saying star, so we want to only select the city comma state from station. And I'm using DB2 as a flavor for SQL here. The most popular would be my SQL, so you can do that as well. And be careful because you're going to lose a thing, so you want to copy if you change. Run code here first to make sure it's correct before you submit. As you can see now, we selected the city and state columns. Simply follow the syntax, select, followed by the columns you want to show the data for from, and then the name of the table. You can comma separate every column name. So we got the city, and then we got the state. Too bad this output doesn't put a like a bar separating these two, but it's actually two separate columns being selected. They're not one thing, so be careful with that. So once you think everything's fine, just click submit code. And that's it for Weather Observation Station 1.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: