SQL 프로젝트를 하면서 SQL에 대한 부족함을 많이 느끼는 중이다.
프로젝트를 하면서 나오는 함수들을 배워보고자 한다.
- 가설1. 어떤 시간대에 이용건수가 높을까?
우선 2023-06-14 18:27:05라 되어 있는 날짜 데이터들을 18이라는 시간 만으로 보고싶다.
그럴 때는 EXTRACT 함수를 사용한다.
EXTRACT(원하는 것 FROM 날짜데이터)
SELECT
EXTRACT(HOUR FROM rental_date) AS hour_of_day,
COUNT(*) AS rental_count,
FROM
자전거_대여내역
where using_minute <> 0 and using_distance <> 0
and birth_year >= 1944
and birth_year <= 2010
GROUP BY
hour_of_day;


=> 오후 6시[18시]에 가장 높은 이용률을 보인다.
- 가설2. 오후 6시에 어느 자치구가 가장 많은 이용을 할까?
18시 기준 대여 내역, 대여소 상세 정보를 봐야겠다.
create view 18시기준 as
select
EXTRACT(HOUR FROM a.rental_date) AS hour_of_day,
a.bike_id, a.stop_id, a.stop_name, a.using_minute, a.using_distance, a.birth_year, a.gender, a.user_type,
b.district, b.district_detail, b.latitude, b.longitude, b.qr_lcd
from 자전거_대여내역 as a
inner join 대여소_정보 as b
on a.stop_id = b.stop_id
where 1=1
and using_minute <> 0
and using_distance <> 0
and birth_year >= 1944 and birth_year <= 2010
having hour_of_day = 18
order by stop_id

- 위자료들을 토대로 LOOKER STUDIO 활용하여 지역별 이용 현황 가시화를 해보자

18시에 강서구 종로구 중구 순으로 높음을 볼 수 있다.
- 강서구, 중구, 종로구 어느 연령대가 가장 높을까?
create view 20대 #30대 as
select EXTRACT(HOUR FROM a.rental_date) AS hour_of_day, a.bike_id, a.stop_id, a.stop_name, a.stop_return_id,a.stop_return_name, a.using_minute, a.using_distance, a.birth_year, a.gender, a.user_type, b.district, b.district_detail, b.qr_lcd
from 자전거_대여내역 as a
inner join 대여소_정보 as b
on a.stop_id = b.stop_id
where using_minute<>0 and using_distance<>0 and birth_year >= 1994 #1984 and birth_year <= 2003 #1993
select count(*) from 20대 #30대 order by count(*) desc limit 1

20, 30대 연령이 가장 높다.
배운점
가설을 어떻게 깊이있게 세우고 논리적으로 나아가는지... 어렵다
응용하는 것이 생각처럼 잘 되지 않았다. 더 연습한다...
join을 쓸일이 많구나 join... 더 연습한다...
'성동1기 전Z전능 데이터 분석가 과정' 카테고리의 다른 글
| [성동1기 전Z전능 데이터 분석가] 30일차 python 기초 - 자료형 (0) | 2023.11.24 |
|---|---|
| [성동1기 전Z전능 데이터 분석가] 29일차 SQL 프로젝트 보고서 및 발표 후 생각 (0) | 2023.11.23 |
| [성동1기 전Z전능 데이터 분석가] 27일차 SQL 프로젝트 EDA 전처리 (0) | 2023.11.21 |
| [성동1기 전Z전능 데이터 분석가] 26일차 SQL 프로젝트 정합성 분석 (0) | 2023.11.20 |
| [성동1기 전Z전능 데이터 분석가] 25일차 SQL.5 (0) | 2023.11.17 |