Loading
Lesson 21
Courses / HackerRank SQL Problem Solving Solution Challenges
Japanese Cities' Attributes | SQL Basic Select | HackerRank Solution

Summary

Summary of Japanese Cities Attributes Exercise

In this exercise, the focus is on querying attributes of Japanese cities from a database table named city. The table contains the following columns: ID, name, country code, district, and population.

Steps Taken

  1. Selecting All Attributes:

    • The initial SQL query is designed to retrieve all columns from the city table using SELECT *.
  2. Filtering for Japanese Cities:

    • To filter the results specifically for Japanese cities, a WHERE clause is added:
      SELECT * FROM city WHERE country_code = 'JP';
      
    • The identifier 'JP' is used to specify that only cities from Japan should be included in the results.
  3. Visualizing Data:

    • Upon executing the query, only rows corresponding to Japanese cities are displayed, demonstrating successful filtering based on the country code.

By following these steps, the exercise effectively retrieves all attributes of cities located in Japan from the dataset.

Video Transcript

Hey everybody, I will do the exercise Japanese cities attributes from the subsection basic select of the section sequel from hacker rink. So let's get started. So we're given this table city that has these columns ID name, country code, district, population and then we're asked to query all attributes of average Japanese city in a city table and the country code to Japan's JP in. So basically want to query to Japanese cities and to do that let's get started with a select star from the name of the table that city. I want to visualize what the data looks like. So as you can see here each row has information about the cities and it includes there's different cities from different countries and I think the district is like the state equivalent here and we're interested here in all the attributes, attributes meaning columns. Okay so we're just going to leave the star there select star all columns of every Japanese city. Now to get a Japanese city there's many cities from around the world here we only want to get the one from Japan so we have to add a where here a filter to filter only the Japanese ones and we can do that through the column country code country code equal to JP N because the Japanese cities the roles Japanese cities will have a JP N for the country code. Okay so let's run the code and there you go we get only the rows there are from Japan. I'm gonna click submit code and that's Japanese cities attributes
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: