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 | 31 |
Tags
- DFS
- 튜토리얼
- TEAM-EDA
- 나는리뷰어다
- pytorch
- MySQL
- 큐
- DilatedNet
- Segmentation
- 엘리스
- 추천시스템
- 스택
- Semantic Segmentation
- TEAM EDA
- Machine Learning Advanced
- hackerrank
- 협업필터링
- 나는 리뷰어다
- Object Detection
- 한빛미디어
- 3줄 논문
- 입문
- 알고리즘
- 프로그래머스
- 파이썬
- eda
- Recsys-KR
- 코딩테스트
- Image Segmentation
- Python
Archives
- Today
- Total
TEAM EDA
[HackerRank] Basic Select : Weather Observation Station 1~12 본문
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
Q1. Query a list of CITY and STATE from the STATION table.
SELECT CITY, STATE FROM STATION;
Q3. 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 ID % 2 = 0
GROUP BY CITY;
Q4. Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table. For example, if there are three records in the table with CITY values 'New York', 'New York', 'Bengalaru', there are 2 different city names: 'New York' and 'Bengalaru'. The query returns 1, because total number of records - number of unique city names = 3 - 2 = 1
SELECT COUNT(CITY) - COUNT(DISTINCT CITY) FROM STATION;
Q5. 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. Sample Input
Sample Input
For example, CITY has four entries: DEF, ABC, PQRS and WXY.
Sample Output
ABC 3
PQRS 4
Explanation
When ordered alphabetically, the CITY names are listed as ABC, DEF, PQRS, and WXY, with lengths 3, 3, 4 and 3. The longest name is PQRS, but there are 3 options for shortest named city. Choose ABC, because it comes first alphabetically.
Note
You can write two separate queries to get the desired output. It need not be a single query.
SELECT CITY, CHAR_LENGTH(CITY)
FROM STATION
ORDER BY 2 ASC, 1 LIMIT 1;
SELECT CITY, CHAR_LENGTH(CITY)
FROM STATION
ORDER BY 2 DESC, 1 DESC LIMIT 1;
Q6. 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 CITY REGEXP '^[aeiou]';
Q7. 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 CITY REGEXP '[aeiou]$';
Q8. 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 '^[aeiou]' AND CITY REGEXP '[aeiou]$';
Q9. 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 '^[^aeiou]';
Q10. 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 '[^aeiou]$';
Q11. 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.
SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP '^[^aeiou]' OR CITY REGEXP '[^aeiou]$';
Q12. Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates.
SELECT DISTINCT CITY FROM STATION
WHERE CITY REGEXP '^[^aeiou]' AND CITY REGEXP '[^aeiou]$';
'EDA Study > SQL' 카테고리의 다른 글
[HackerRank] Basic Select : Employee Names (0) | 2021.02.07 |
---|---|
[HackerRank] Basic Select : Higher Than 75 Marks (0) | 2021.02.07 |
[HackerRank] Basic Select : Japanese Cities' Names (0) | 2021.02.07 |
[HackerRank] Basic Select : Japanese Cities' Attributes (0) | 2021.02.07 |
[HackerRank] Basic Select : Select By ID (0) | 2021.02.07 |