일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- pythonanywhere
- blog
- c#
- python3
- delphi 10.3
- 중복제거
- GIT
- advColumnGrid
- hackerrank
- queryset
- Django
- PyCharm
- dbadvgrid
- Delphi
- TMS
- declare
- 델파이
- Push
- HTML
- github
- pyhcarm
- MSSQL
- COMMIT
- templates
- rank
- Visual Studio
- 백준
- get_object_or_404
- anaconda3
- python 3.7
- Today
- Total
DevHyun
Weather Observation Station 4 본문
www.hackerrank.com/domains/sql
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 records - number of unique city names = 3 - 2 = 1
번역 : STATION 테이블에서 CITY의 총 갯수에서 중복제거된 CITY의 갯수를 뺀 값은?
MSSQL
풀이 : 예를들면 STATION 테이블의 총 COUNT는 3이고 각각 값들이 KOREA, JAPAN, KOREA라면 중복제거된 CITY의 갯수는 2일 것임!
이런 계산은 처음해봐서 당황했다!
나의 첫 답은 SELECT COUNT(*) - COUNT(CITY) FROM STATION 이었는데
완전히 달랐음... 문제 이해를 잘 못했던 것 같음!
SELECT COUNT(CITY) - COUNT(DISTINCT CITY)
FROM STATION
'SQL > HACKERRANK' 카테고리의 다른 글
Occupations (0) | 2020.11.03 |
---|---|
Print Prime Numbers (0) | 2020.10.29 |
Draw The Triangle 1 (0) | 2020.10.29 |
Weather Observation Station 5 (0) | 2020.10.29 |
Weather Observation Station 3 (0) | 2020.10.29 |