Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- GSQL101
- 오라클 물음표
- cx_oracle 에러
- graphDB
- oracle printed ????
- 타이거그래프
- 오라클한글깨짐
- 오라클LANG
- hackerrank
- neo4jcertificate
- Tigergraph GSQL
- SQL연습
- hackerrankTypeofTriangle
- dpi-1072 version is unsupported windows
- TigerGraph
- 그래프데이터베이스
- hackerrankTypeofTrianglesolution
- DPI-1047
- oracle ????
- HackerrankSQL
- cx_oracle python oracle error
- neo4jcypher
- neo4j
- hackerranckSQL
- neo4j자격증
- GSQL
- DPI-1072
- how to DPI-1072
- how to DPI-1047
- 오라클???출력
Archives
- Today
- Total
song's note
[Hackerrank - SQL] weather observation station 11 본문
Weather Observation Station 11 | HackerRank
Query a list of CITY names not starting or ending with vowels.
www.hackerrank.com
문제
Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates.
CITY가 모음으로 시작하지 않거나 모음으로 끝나지 않는 CITY 를 중복없이 나열하라
풀이
SELECT DISTINCT CITY
FROM STATION
WHERE SUBSTR(LOWER(CITY), 1, 1) NOT IN ('a', 'e', 'i', 'o', 'u')
OR SUBSTR(LOWER(CITY), -1, 1) NOT IN ('a', 'e', 'i', 'o', 'u') ;
/*
WHERE NOT REGEXP_LIKE(lower(CITY), '^[aeiou]', 'i')
OR NOT REGEXP_LIKE(CITY, '[aeiou]$') ;
*/
계속 풀었던 방식으로 SUBSTR과 LOWER, 그리고 IN을 사용해서 풀었는데
자꾸 틀렸다고 해서 다른 사람들의 풀이를 찾아봤다.
알고보니 문제를 잘못 읽어서 계속 AND 조건으로 풀고 있었기에 오류가 났던 것이었는데 ,
그것을 발견하기 전까지는 어떤 것을 해도 통과가 안되었다.
그런 시행착오중에서 정규표현식을 이용해서 문제를 푼 사람들의 글을 보게 되었다.
솔직히 SQL 에서 정규표현식이 가능한지도 몰랐는데...
이 문제에서 쓴
REGEXP_LIKE 는 문자열이 정규표현식의 조건에 부합하는지 체크하는 함수이며 WHERE 절에서 쓰일 수 있다.
나중에 SQL정규표현식에 대해서도 공부해봐야겠다.
'공부 > SQL' 카테고리의 다른 글
| [Hackerrank - SQL] Type of Triangle (0) | 2022.06.21 |
|---|---|
| [Hackerrank - SQL] Higher Than 75 Marks (0) | 2022.04.09 |
| [Hackerrank - SQL] weather observation station 7 (0) | 2022.04.09 |
| [Hackerrank - SQL] weather observation station 6 (0) | 2021.12.10 |
| [Hackerrank - SQL] weather observation station 5 (0) | 2021.12.10 |