[HackerRank][SQL(Oracle)] Select All, Select By ID, Revising the Select Query I&II, Revising Aggregations, Average Population, Population Density Difference

728x90

 

※  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

https://www.hackerrank.com/challenges/revising-aggregations-the-count-function/problem?isFullScreen=true 

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

https://www.hackerrank.com/challenges/revising-aggregations-the-average-function/problem?isFullScreen=true 

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;

 

 

반응형