Weather Observation Station 4까지 풀이
Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA
SELECT *
FROM CITY
WHERE POPULATION >= 100000
AND COUNTRYCODE = 'USA';
Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA.
SELECT NAME
FROM CITY
WHERE POPULATION > 120000
AND COUNTRYCODE = 'USA';
Query all columns (attributes) for every row in the CITY table.
SELECT *
FROM CITY;
Query all columns for a city in CITY with the ID 1661.
SELECT *
FROM CITY
WHERE ID = '1661';
Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN.
SELECT *
FROM CITY
WHERE COUNTRYCODE = 'JPN';
Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.
SELECT NAME
FROM CITY
WHERE COUNTRYCODE ='JPN';
Query a list of CITY and STATE from the STATION table.
SELECT CITY
, STATE
FROM STATION;
Query a list of CITY and STATE from the STATION table.
SELECT CITY
, STATE
FROM STATION;
Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.
SELECT CITY
FROM STATION
WHERE MOD(ID, 2) = 0
GROUP BY CITY;
-- MySQL의 경우 %연산이 가능하지만 Oracle의 경우 MOD() 함수를 사용해야함...!
SELECT CITY
FROM STATION
WHERE ID%2 = 0
GROUP BY CITY;
Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
SELECT COUNT(CITY) - COUNT(DISTINCT(CITY))
FROM STATION;