반응형
Query the list of CITY names starting with vowels (i.e., a, e, i, o, or u) from STATION. Your result cannot contain duplicates.
Input Format
The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.
select distinct city from station where city REGEXP '^[aeiouAEIOU]';
- SELECT DISTINCT CITY: 중복된 도시 이름 제거.
- WHERE CITY REGEXP '^[aeiouAEIOU]': 도시 이름이 모음으로 시작하는지 정규 표현식으로 필터링함.
- ^는 문자열의 시작.
- [aeiouAEIOU]는 소문자와 대문자 모음 포함.
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 CITY REGEXP '^[aeiouAEIOU].*[aeiouAEIOU]$'
- SELECT DISTINCT CITY: 중복된 도시 이름 제거.
- REGEXP '^[aeiouAEIOU].*[aeiouAEIOU]$'
- ^는 문자열의 시작.
- [aeiouAEIOU]는 첫 글자가 모음인지 확인.
- .*는 중간 글자 아무거나 허용.
- $는 문자열 끝.
- 마지막 글자도 모음인지 확인.
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 CITY REGEXP '^[^aeiouAEIOU]';
- SELECT DISTINCT CITY: 중복된 도시 이름 제거.
- REGEXP '^[^aeiouAEIOU]':
- ^는 문자열의 시작을 의미.
- [^...]는 괄호 안에 있는 문자 제외.
- 즉, 첫 글자가 모음이 아닌 도시를 찾는 조건.
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 CITY REGEXP '[^aeiouAEIOU]$';
- SELECT DISTINCT CITY: 중복 없이 도시 이름만 조회.
- REGEXP '[^aeiouAEIOU]$':
- $는 문자열의 끝을 의미.
- [^aeiouAEIOU]는 모음을 제외한 문자, 즉 자음.
- 따라서 CITY 이름이 자음으로 끝나는 경우만 반환합니다.
반응형
'Computer Science > SQL' 카테고리의 다른 글
SQL | HackerRank MAX(CASE WHEN…)을 활용한 피벗(Pivot) 쿼리 (0) | 2025.06.15 |
---|---|
SQL | HackerRank 문자열을 이어붙이기 (CONCAT) (0) | 2025.06.14 |
SQL | HackerRank 가장 짧고 긴 도시 이름 찾기 – 문자열 길이 기반 SQL 정렬과 조건 추출 (1) | 2025.06.12 |
SQL | HackerRank 삼각형 분류하기: 조건문 CASE를 활용한 다중 조건 처리 (0) | 2025.06.11 |
SQL | LeetCode 1327. 특정 월 기준 주문량 분석하기 (0) | 2025.06.10 |