일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- queryset
- blog
- GIT
- MSSQL
- templates
- PyCharm
- c#
- github
- 중복제거
- python3
- anaconda3
- rank
- get_object_or_404
- Visual Studio
- Django
- dbadvgrid
- Delphi
- Push
- TMS
- pythonanywhere
- hackerrank
- declare
- python 3.7
- 델파이
- COMMIT
- advColumnGrid
- delphi 10.3
- pyhcarm
- 백준
- HTML
- 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 |