본문 바로가기
나도 Data scientist ?/Self study

SQL 점심 study 1 _20220116

by 인사 잘하는 라이언 2023. 1. 26.
728x90
반응형

SQL 점심 study 1 _20220116

 

1. 해석하기 / chk_yn = 진단여부

select usr_grade , count(distinct rgsid)as cnt

from "000000-bidw".0000_car

where ad_date_first >= date'2022-01-01'

and ad_date_first < date'2023-01-01'

and chk_yn is null group by usr_grade

 

<해석>

usr_grade 데이터를 볼건데

- rgsid가 중복되지 않게, cnt라는 컬럼으로 출력.

000000-bidw라는 곳에서 데이터 추출하는데

ad_date_first(최초광고등록일), 2022년 1월 1일부터 ~2023년 1월 1일 이전까지(2022년 전체)

진단여부 값은 없다?(null)

usr_grade 기준으로 카운트

= 2022년 전체 usr_grade 중 rgsid가 중복되지 않는 것이 cnt라는 열로 데이터 추출

 

2. 쿼리짜오기

2022년에 광고등록된 차량 이고 chk is null 인 조건중에서 광고등록월별(ad_date_first) ,회원등급별 등록대수 뽑아보기 순서 정리는 월별 회원등급별 순으로 보이게 오름차순으로

 

<쿼리>

select date_trunc(‘month, ad_date_first) count(usr_grade) as cnt

from “000000-bidw”.00000_car

where ad_date_first >= date’2022-01-01’

and ad_date_first <date’2023-01-1’

and chk_yn is null

group by usr_grade

order by cnt asc;

반응형

댓글