티스토리 뷰
Weather Observation Station 1
Query a list of CITY and STATE from the STATION table.
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
SELECT CITY, STATE
FROM STATION;
Weather Observation Station 3
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.
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 ID % 2 = 0;
Weather Observation Station 4
Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
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 , because .
total number of recodes - number of unique city name = 3 -2 = 1
SELECT COUNT(*) - COUNT(DISTINCT(CITY))
FROM STATION;
Weather Observation Station 5
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.
The STATION table is described as follows:
where LAT_N is the northern latitude and LONG_W is the western longitude.
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 and . The longest name is PQRS, but there are 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, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY), CITY
LIMIT 1;
SELECT CITY, LENGTH(CITY)
FROM STATION
ORDER BY LENGTH(CITY) DESC, CITY
LIMIT 1;
Weather Observation Station 6
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 REGEXP_LIKE(CITY, '^[aeiouAEIOU]')
ORDER BY CITY
Weather Observation Station 7
Query the list of CITY names ending with vowels (a, e, i, o, 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 REGEXP_LIKE(CITY, '[aeiouAEIOU]$')
ORDER BY CITY
Weather Observation Station 8
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.
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 REGEXP_LIKE(CITY, '^[aeiouAEIOU]')
AND REGEXP_LIKE(CITY, '[aeiouAEIOU]$');
Weather Observation Station 9
Query the list of CITY names from STATION that do not start with vowels. 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 NOT REGEXP_LIKE(CITY,'^[aeiouAEIOU]');
Weather Observation Station 10
Query the list of CITY names from STATION that do not end with vowels. 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 NOT REGEXP_LIKE(CITY,'[aeiouAEIOU]$');
Weather Observation Station 11
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.
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 NOT (REGEXP_LIKE(CITY,'^[aeiouAEIOU]')
AND REGEXP_LIKE(CITY,'[aeiouAEIOU]$'));
Weather Observation Station 12
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.
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 NOT REGEXP_LIKE(CITY, '^[aeiouAEIOU]')
AND NOT REGEXP_LIKE(CITY, '[aeiouAEIOU]$')
ORDER BY CITY;
'Programming > MySQL' 카테고리의 다른 글
[MySQL/Hackerrank] Occupations (0) | 2021.11.02 |
---|---|
[MySQL/Hackerrank] The PADS (0) | 2021.11.02 |
[MySQL/Hackerrank] Type of Triangle (0) | 2021.11.02 |
[MySQL/Hackerrank] Higher Than 75 Marks, Employee Names, Employee Salaries (0) | 2021.11.02 |
[MySQL/Hackerrank] Revising the Select Query (0) | 2021.11.02 |
- Total
- Today
- Yesterday
- 몰누피라비르
- hackerrank
- HK이노엔
- 동국알앤에스
- python3
- 에코캡
- DATABASE
- Tableau
- 넷플릭스
- 리비안
- 매매일지
- MSSQL
- MS SQL Server
- 테슬라
- 대원화성
- mysql
- Weather Observation Station
- 분석탭
- tensorflow
- 경구치료제
- SQL Server
- TSQL
- 넥스트BT
- 해커랭크
- list
- insert
- string
- python
- 미중무역전쟁
- 코로나19
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |