※ The CITY table is described as follows:
■ [Basic Select] Select All
https://www.hackerrank.com/challenges/select-all-sql/problem?isFullScreen=true
Q.
Query all columns (attributes) for every row in the CITY table.
A.
SELECT * FROM CITY;
■ [Basic Select] Select By ID
https://www.hackerrank.com/challenges/select-by-id/problem?isFullScreen=tru
Q.
Query all columns for a city in CITY with the ID 1661.
A.
SELECT * FROM CITY WHERE ID = 1661;
■ [Basic Select] Revising the Select Query I
https://www.hackerrank.com/challenges/revising-the-select-query/problem?isFullScreen=true
Q.
Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA.
A.
SELECT * FROM CITY WHERE POPULATION > 100000 AND COUNTRYCODE = 'USA';
■ [Basic Select] Revising the Select Query II
https://www.hackerrank.com/challenges/revising-the-select-query-2/problem?isFullScreen=true
Q.
Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
A.
SELECT NAME FROM CITY WHERE POPULATION > 120000 AND COUNTRYCODE = 'USA';
■ [Aggregation] Revising Aggregations - The Count Function
Q.
Query a count of the number of cities in CITY having a Population larger than 100000.
A.
SELECT COUNT(*) FROM CITY WHERE POPULATION > 100000;
■ [Aggregation] Revising Aggregations - The Sum Function
https://www.hackerrank.com/challenges/revising-aggregations-sum/problem?isFullScreen=true
Q.
Query the total population of all cities in CITY where District is California.
A.
SELECT SUM(POPULATION) FROM CITY WHERE DISTRICT = 'California';
■ [Aggregation] Revising Aggregations - Averages
Q.
Query the average population of all cities in CITY where District is California.
A.
SELECT AVG(POPULATION) FROM CITY WHERE DISTRICT = 'California';
■ [Aggregation] Average Population
https://www.hackerrank.com/challenges/average-population/problem?isFullScreen=true
Q.
Query the average population for all cities in CITY, rounded down to the nearest integer.
A.
SELECT ROUND(AVG(POPULATION)) FROM CITY;
■ [Aggregation] Population Density Difference
https://www.hackerrank.com/challenges/population-density-difference/problem?isFullScreen=true
Q.
Query the difference between the maximum and minimum populations in CITY.
A.
SELECT MAX(POPULATION) - MIN(POPULATION) FROM CITY;
'코딩 문제 풀기 ( Algorithm problem solving ) > 해커랭크 ( HackerRank )' 카테고리의 다른 글
[HackerRank][SQL(Oracle)] The Blunder (0) | 2023.03.27 |
---|---|
[HackerRank][SQL(Oracle)] Employee Names, Employee Salaries, Top Earners (0) | 2023.03.27 |
[HackerRank][SQL(Oracle)] Higher Than 75 Marks (0) | 2023.03.27 |
[HackerRank][SQL(Oracle)] Weather Observation Station 13~20 (0) | 2023.03.26 |
[HackerRank][SQL(Oracle)] Weather Observation Station 1~12 (0) | 2023.03.25 |