select *
from CITY
where POPULATION > 100000 and COUNTRYCODE = "USA"
select NAME
from CITY
where POPULATION > 120000 and COUNTRYCODE = "USA"
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 names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.
SELECT DISTINCT CITY
FROM STATION
WHERE ID % 2 = 0
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
Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.
(SELECT CITY,
LENGTH(CITY) AS LEN
FROM STATION
ORDER BY LEN, CITY
LIMIT 1)
UNION
(SELECT CITY,
LENGTH(CITY) AS LEN2
FROM STATION
ORDER BY LEN2 DESC, CITY
LIMIT 1)
문자열 길이를 추출하는 함수는 LENGTH이다.
Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.
SELECT DISTINCT CITY
FROM STATION
WHERE LEFT(CITY,1) IN ("A", "E", "I", "O", "U")
Query the list of CITY names ending with vowels (a, e, i, o, u) from STATION. Your result cannot contain duplicates.
SELECT DISTINCT CITY
FROM STATION
WHERE RIGHT(CITY,1) IN ("a", "e", "i", "o", "u")
Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates.
SELECT DISTINCT CITY
FROM STATION
WHERE LEFT(CITY,1) IN ("A", "E", "I", "O", "U") AND RIGHT(CITY,1) IN ("a", "e", "i", "o", "u")
Query the list of CITY names from STATION that do not start with vowels. Your result cannot contain duplicates.
SELECT DISTINCT CITY
FROM STATION
WHERE LEFT(CITY,1) NOT IN ("A", "E", "I", "O", "U")
Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates.
SELECT DISTINCT CITY
FROM STATION
WHERE RIGHT(CITY,1) NOT IN ("a", "e", "i", "o", "u")
| [10주차]해커랭크: 26 ~ 35 (0) | 2023.03.03 |
|---|---|
| [9주차]해커랭크 16 ~ 25(Basic Select, Aggregation) (0) | 2023.02.12 |
| [7주차] 리트코드: Day5 ~ Day9(1407, 1158) (0) | 2022.12.12 |
| [6주차]리트코드: day1 ~ day4 (0) | 2022.12.08 |
| [5주차] 프로그래머스: JOIN, STRING, DATE (0) | 2022.12.08 |