본문 바로가기

SQL30

[solvesql - day 19] 전국 카페 주소 데이터 정제하기 https://solvesql.com/problems/refine-cafe-address/ https://solvesql.com/problems/refine-cafe-address/ solvesql.com-- 카페 데이터를 기반으로, 각 지역(시도, 시군구)별 카페 수를 계산하고,-- 카페 수가 많은 순서대로 정렬하여 출력SELECT -- 'address' 컬럼에서 첫 번째 공백(' ') 전까지의 문자열을 'sido'로 추출 -- 'sido'는 대한민국에서 시도를 나타냄 substr(address, 1, instr(address, ' ') - 1) AS sido, -- 'address'에서 첫 번째 공백 뒤의 문자열 중, 두 번째 공백 전까지의 문자열을 'sigungu'로 추출 .. 2025. 1. 11.
[solvesql - day 18] 펭귄 날개와 몸무게의 상관 계수 https://solvesql.com/problems/correlation-penguin/ https://solvesql.com/problems/correlation-penguin/ solvesql.com-- 펭귄 데이터에서 종별로-- 날개 길이와 몸무게 사이의 상관계수(Correlation Coefficient)를 계산WITH avg_peng AS ( -- 각 펭귄의 종별 평균 날개 길이와 평균 몸무게를 계산한 임시 테이블 SELECT species, -- 펭귄의 종 (예: Adelie, Chinstrap, Gentoo) flipper_length_mm, -- 날개 길이(mm) AVG(flipper_length_mm).. 2025. 1. 11.
[solvesql - day 17] 멀티 플랫폼 게임 찾기 https://solvesql.com/problems/multiplatform-games/ https://solvesql.com/problems/multiplatform-games/ solvesql.com-- platform_id-- sony : 14, 15, 16, 17-- nintendo : 1, 3, 22, 23-- microsoft : 24, 26-- 데이터 베이스에 'XONE' 이 'Xone'이라 되어 있어 platform_id인 26을 넣을시 오류 존재-- 2012년 이후 주요 플랫폼(소니, 닌텐도, 마이크로소프트)에서 출시된 게임을 식별하고-- 최소 2개 이상의 주요 플랫폼에서 출시된 게임 목록을 조회WITH sony AS ( -- 소니(Sony)의 주요 플랫폼에서 출시된 게임 목록 .. 2025. 1. 11.
[solvesql - day 16] 스테디셀러 작가 찾기 https://solvesql.com/problems/find-steadyseller-writers/ https://solvesql.com/problems/find-steadyseller-writers/ solvesql.com-- Fiction 장르의 책을 저자별로 연속 출판된 최소 5권 이상의 시리즈를 확인WITH dist AS ( -- Fiction 장르의 중복되지 않은 저자와 출판 연도를 가져오는 임시 테이블 SELECT DISTINCT author, -- 저자 이름 year -- 출판 연도 FROM books -- 책 정보 테이블 WHERE genre = 'Fict.. 2025. 1. 11.
[solvesql - day 15] 폐쇄할 따릉이 정류소 찾기 2 https://solvesql.com/problems/find-unnecessary-station-2/ https://solvesql.com/problems/find-unnecessary-station-2/ solvesql.com-- 자전거 정류소(station)별로 2018년 10월과 2019년 10월의 대여 및 반납 데이터를 비교하여 -- 이용률 변화(usage_pct)가 50% 이하인 정류소 조회WITH rent_bike AS ( -- 자전거 대여 데이터 집계 SELECT rent_station_id, -- 대여 정류소 ID SUM( CASE strftime('%Y-%m', rent_at) -- 대여 날짜(rent_at)에서 연월을 추출 .. 2025. 1. 11.
[solvesql - day 14] 전력 소비량 이동 평균 구하기 https://solvesql.com/problems/moving-average-of-power-consumption/ https://solvesql.com/problems/moving-average-of-power-consumption/ solvesql.com-- 특정 기간 동안 전력 소비 데이터를 10분 간격으로 평균 계산SELECT datetime(measured_at, '+10 minute') AS end_at, -- 측정 시각(measured_at)에 10분을 더한 값을 end_at 열로 표시 ROUND( AVG(zone_quads) OVER ( ORDER BY measured_at ROWS BETWEEN 5 PRECEDI.. 2025. 1. 11.