25%
66,000원
다른 수강생들이 자주 물어보는 질문이 궁금하신가요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
수료증
수료증 주나요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
CLI로 ga_export.sql 쉽게 불러오기
안녕하세요 강사님, 오늘부터 새로 강의를 듣게 되었는데 완강 목표로 열심히 듣겠습니다 ㅎㅎ강의 초반 환경설정에서 ga_export.sql이 large text여서 Dbeaver에서 스크립트 실행할 때 java heap space 부족 에러가 발생하더라고요.이 때 터미널로 쉽게 불러올 수 있는 방법을 찾았고, 다른 수강생분들에게도 도움이 될 것 같아 공유드립니다.아래 스샷처럼 터미널에서 sudo -iu postgres psql 입력 후 \i [ga_export.sql이 위치한 경로] 를 입력하면 쉽게 ga 데이터를 불러올 수 있습니다.
- 미해결다양한 사례로 익히는 SQL 데이터 분석
컬럼의 뜻에 대해 질문 드립니다.
채널별 고유/주문 사용자 건수와 매출 금액 및 비율 SQL로 구하기 2 를 학습하면서/************************************ 채널별 고유 사용자 건수와 매출금액 및 비율, 주문 사용자 건수와 주문 매출 금액 및 비율 채널별로 고유 사용자 건수와 매출 금액을 구하고 고유 사용자 건수 대비 매출 금액 비율을 추출. 또한 고유 사용자 중에서 주문을 수행한 사용자 건수를 추출 후 주문 사용자 건수 대비 매출 금액 비율을 추출 *************************************/ with temp_01 as ( select a.sess_id, a.user_id, a.channel_grouping , b.order_id, b.order_time, c.product_id, c.prod_revenue from ga_sess a left join orders b on a.sess_id = b.sess_id left join order_items c on b.order_id = c.order_id where a.visit_stime >= (:current_date - interval '30 days') and a.visit_stime < :current_date ) select channel_grouping , sum(prod_revenue) as ch_amt -- 채널별 매출 --, count(distinct sess_id) as ch_sess_cnt -- 채널별 고유 세션 수 , count(distinct user_id) as ch_user_cnt -- 채널별 고유 사용자 수 --, count(distinct case when order_id is not null then sess_id end) as ch_ord_sess_cnt -- 채널별 주문 고유 세션수 , count(distinct case when order_id is not null then user_id end) as ch_ord_user_cnt -- 채널별 주문 고유 사용자수 --, sum(prod_revenue)/count(distinct sess_id) as ch_amt_per_sess -- 접속 세션별 주문 매출 금액 , sum(prod_revenue)/count(distinct user_id) as ch_amt_per_user -- 접속 고유 사용자별 주문 매출 금액 -- 주문 세션별 매출 금액 --, sum(prod_revenue)/count(distinct case when order_id is not null then sess_id end) as ch_ord_amt_per_sess -- 주문 고유 사용자별 매출 금액 , sum(prod_revenue)/count(distinct case when order_id is not null then user_id end) as ch_ord_amt_per_user from temp_01 group by channel_grouping order by ch_user_cnt desc;위 쿼리의 쿼리 뜻이 잘 이해가 안되어 질문 드립니다., sum(prod_revenue)/count(distinct user_id) as ch_amt_per_user -- 접속 고유 사용자별 주문 매출 금액, sum(prod_revenue)/count(distinct case when order_id is not null then user_id end) as ch_ord_amt_per_user이 두 항목은 각각 접속 고유 사용자별 주문 매출 금액,주문 고유 사용자별 매출 금액이라 명칭 되어 있는데, 어떤 의미를 가지고 있는 것인지 잘 이해가 되지 않아 질문 드립니다.접속 고유 사용자별 주문 매출 금액 : 사용자 대비 30일이내 매출 금액주문 고유 사용자별 매출 금액 : 주문 대비 30일 이내 매출 금액이렇게 이해를 하면 될런지요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
group by에 대해 질문 드립니다.
사용자별 월별 세션 접속 횟수의 구간별 분포 집계 SQL로 구하기 - 02위 과정을 학습하고 있습니다select month ,case when monthly_user_cnt = 1 then '0_only_first_session' when monthly_user_cnt between 2 and 3 then '2_between_3' when monthly_user_cnt between 4 and 8 then '4_between_8' when monthly_user_cnt between 9 and 14 then '9_between_14' when monthly_user_cnt between 15 and 25 then '15_between_25' when monthly_user_cnt >= 26 then 'over_26' end as gubun , count(*) as user_cnt from temp_01 group by month, case when monthly_user_cnt = 1 then '0_only_first_session' when monthly_user_cnt between 2 and 3 then '2_between_3' when monthly_user_cnt between 4 and 8 then '4_between_8' when monthly_user_cnt between 9 and 14 then '9_between_14' when monthly_user_cnt between 15 and 25 then '15_between_25' when monthly_user_cnt >= 26 then 'over_26' end order by 1, 2;위 쿼리에서 group by 항목이 이해가 잘 안되서 질문 드립니다.위와 같이 그룹을 지으면일자 + monthly_user_cnt 의 조합으로 그룹들이 만들어짐select에서select month ,case when monthly_user_cnt = 1 then '0_only_first_session' when monthly_user_cnt between 2 and 3 then '2_between_3' when monthly_user_cnt between 4 and 8 then '4_between_8' when monthly_user_cnt between 9 and 14 then '9_between_14' when monthly_user_cnt between 15 and 25 then '15_between_25' when monthly_user_cnt >= 26 then 'over_26' end as gubun위 쿼리로 넘어온 데이터(아직 컬럼으로 만들어지지 않은채 각 그룹별로 정의되어 넘어온 데이터)에 컬럼명을 붙여줌위와 같은 동작을 하는게 맞는지요?제가 이해하는게 맞는지 알고 싶습니다.
- 미해결다양한 사례로 익히는 SQL 데이터 분석
로드맵을 따라 두 강의를 따라 학습을 하고 있습니다.
데이터 분석 sql fundamentals의 다운받은 자료는 한글이 깨지지 않던데, 지금 강의는 다운받고 압축을 풀어보면 주석에 있는 한글이 다 깨져 있습니다.강의를 보면서 한글이 보일때마다 최대한 수정을 해보려 하는데... 강의에 안보이는 한글 주석들이 꽤 있습니다.저만 그런건지 확인 부탁 드리고 싶습니다.제 환경은 윈도우11, 반디집으로 압축을 풀었습니다.
- 미해결다양한 사례로 익히는 SQL 데이터 분석
현재 모든 판다스 파일에 오류가 발생되는것 같습니다.
어제 장문의 글을 올렸는데 이유는 모르겠으나 찾아볼수가 없어서 다시 작성을 합니다.현재 sqlalchemy의 문법 강제성의 이유로 2.0.0 버전 이후로는 사용하신 방법으로는 실행이 되지 않습니다.이에 2.0.0 이전 버전으로 다운그레이 하거나(저는 이 방법이 통하지 않아 다른 방법을 찾아봤습니다)다음과 같은 방법을 사용하면 됩니다.제가 참고한 해외 커뮤니티들에서 제시하는 사용 방법으로는 모든 query에 text() 함수를 사용해 반환된 값을 read_sql_query에 사용하라고 되어 있었는데 테스트 해 보니 현재 작성된 쿼리 스트링으로 사용해도 문제가 없었습니다.import pandas as pd from sqlalchemy import create_engine, text conn_string = 'postgresql://postgres:1324@localhost:5432/inflearn' conn = create_engine(conn_string) postgres_engine = conn.connect()
- 미해결다양한 사례로 익히는 SQL 데이터 분석
SQL 구글 애널리틱스 전체 데이터셋 다운로드
안녕하세요. 완강을 하고 전반적으로 복습을 하는 차원에서 다시 쿼리를 공부하고 있는데 3달이 아닌 전체 데이터세트를 가지고 한 번 해보고 싶어서요. 혹시 구글 애널리틱스 전체 데이터셋을 다운 받을 수 있는 방법이 있을까요 ? 제가 찾아보니까 날짜 하루하루 단위로 다운로드는 가능한데 1년치를 이렇게 다운받는 건 너무 일이 많은 거 같아서 질문드립니다.
- 미해결다양한 사례로 익히는 SQL 데이터 분석
집계 함수 order by
with temp_01as (select d.category_name,to_char(date_trunc('month', a.order_date), 'yyyymm') as month_day,sum(amount) as sum_amount,count(distinct a.order_id) as monthly_ord_cntfrom orders ajoin order_items b on a.order_id = b.order_idjoin products c on b.product_id = c.product_idjoin categories d on c.category_id = d.category_idgroup by d.category_name, to_char(date_trunc('month', a.order_date), 'yyyymm'))select *,sum(sum_amount) over (partition by month_day order by month_day) as temp1,sum(sum_amount) over (partition by month_day) as temp2,sum_amount / sum(sum_amount) over (partition by month_day) as ratiofrom temp_01집계 어날리틱 함수는 order by를 사용하면 파티션 내에서 누적합이 되는것으로 알고 있었는데 왜 이렇게 나올까요...? 제가 혹시 놓친게 있는 걸까요
- 미해결다양한 사례로 익히는 SQL 데이터 분석
date_trunc 사용 이유
order_date 컬럼에 대해 쿼리를 할 때 date_trunc('day', order_date)::date; 로 사용하셨는데 date는 YYYY-MM-DD 형태인데 date_trunc()를 굳이 사용할 필요가 있나요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
실습자료 복원
안녕하세요. 윈도우 11 사용하고 있습니다. 실습 자료를 복원하는데 아래와 같은 문구가 나오면서 안 됩니다 .. 해결방법이 있을까요 ? unrecognized win32 error code: 123pg_restore: error: could not open input file "C:\Users\DS\Documents\???\????_?????_????\data_schema.backup": Invalid argument
- 미해결다양한 사례로 익히는 SQL 데이터 분석
사용자별 월별 세션 접속 횟수의 구간별 분포 집계 SQL관련 질문
안녕하세요 강사님사용자별 월별 세션 접속 횟수의 구간별 분포 집계 SQL 구하고 시각화 하기 - 02 강의 부분에서 질문을 드리려고 하는데요.강사님께서 monthly_user_cnt를 case when으로 범위를 자의적으로 정해서 구분을 하셨는데, 만약 파이썬을 활용하면 히스토그램을 본다던지, value_counts() 등등으로 구분 시도를 할 수 있을 것 같은데, 단지 sql로만 활용을 한다면, 이러한 구분을 어떤 방법으로 하는게 좋을지 알 수 있을까요?예를 들어 강의에서는 1번, 2-3번, 4-8번 이렇게 구분을 하신 이유와 방법에 대해서 알고 싶습니다. 부가적으로 질문을 드리고 싶은게, 보통 with문을 만드실 때 group by 까지는 with 문 안에서 진행을 하시고, order by 같은 경우에는 with 밖에서 쓰시던데, with문 안에서 order by 를 안하는 이유에 대해서 있을까요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
복원 관련 문의
기존 문의사항 보고 작성해주신 답편대로 다 따라햇는데ga_export 용량이 커서 스크립트 업로드가안돼요DBEAVER 용량을 20,000M 이상으로 키울 경우 DBEAVER 실행이안돼요..텍스트 에디터 사용하여 복+붙해도 용량이 크다고안됩니다.해결방법 알려주세요ㅠㅠㅠ
- 미해결다양한 사례로 익히는 SQL 데이터 분석
plotly 결과 그래프가 안보이는 경우
아래처럼 코드를 실행하였을 때, 결과 그래프가 보이지 않습니다. 구글링을 해보니 plotly.offline.init_notebook_mode(connected=False) 이러한 옵션을 넣으면 해결이 된다는데, 해결이 되지 않습니다. 혹시 다른 방법이 있을까요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
'작년 대비 동월 매출 비교 SQL로 구하기' 문의 드립니다.
작년 대비 동월 매출 비교 SQL로 구하기 부분에서lag 함수로 12 row 이전의 데이터를 가져오셨는데,실제 데이터가 특정 월에 매출이 발생하지 않는 케이스를 포함할 경우에는 어떻게 해야할지 문의 드립니다.
- 미해결다양한 사례로 익히는 SQL 데이터 분석
DAU, WAU, MAU를 SQL로 구하기-02 관련 질문드립니다.
withtemp_00 as (select generate_series('2016-08-02'::date, '2016-11-01'::date, '1 days'::interval)::date as current_date)select b.current_date, count(distinct user_id) as daufrom ga_sess across join temp_00 bwhere visit_stime >= (b.current_date - interval '1 days') and visit_stime < b.current_dategroup by b.current_date 위 SQL문에서where visit_stime >= (b.current_date - interval '1 days') and visit_stime < b.current_date이 부분이 이해가 가지 않습니다.current_date가 2016-08-02일 경우visit_stime이 2016-08-02보다는 작아야 하고,2016-08-01보다는 크거나 같다는 말인데..그럼 즉, 2016-08-01 00:00:00 ~2016-08-01 23:59:59 라는 건데요..그럼 이게 2016-08-01의 DAU가 아닌가요?..select 절에서는 current_date로 group by를 해서추출된 데이터는 2016-08-02의 DAU로 추출이 되더라구요..실제 csv파일로 받아서 보아도,2016-08-01의 dau가 1569로 확인이 되는거 같기두 하구요.. withtemp_00 as (select generate_series('2016-08-01'::date, '2016-11-01'::date, '1 days'::interval)::date as current_date)select b.current_date, count(distinct user_id) as daufrom ga_sess across join temp_00 bwhere visit_stime >= b.current_date and visit_stime < (b.current_date + interval '1 days')group by b.current_date withtemp_00 as (select generate_series('2016-08-01'::date, '2016-11-01'::date, '1 days'::interval)::date as current_date)select b.current_date, count(distinct user_id) as waufrom ga_sess across join temp_00 bwhere visit_stime >= (b.current_date - interval '6 days') and visit_stime < (b.current_date + interval '1 days')group by b.current_date; withtemp_00 as (select generate_series('2016-08-01'::date, '2016-11-01'::date, '1 days'::interval)::date as current_date)select b.current_date, count(distinct user_id) as maufrom ga_sess across join temp_00 bwhere visit_stime >= (b.current_date - interval '29 days') and visit_stime < (b.current_date + interval '1 days')group by b.current_date; 이렇게 구하는게 맞는거 아닌지 문의드립니다 !
- 미해결다양한 사례로 익히는 SQL 데이터 분석
고객별 연관 상품 추출 수업 관련 질문
안녕하세요, 주변별 고객별 연관 상품 추출 sql 구하기 -02 수업 관련해서 질문 드리겠습니다.해당 쿼리문 결과값 중 'cnt' 열에 해당되는 횟수가 출력이 되는데, 예를 들면 위 사진에 보이는 출력 열 'cnt' 3에 해당되는 user_id 를 알고 싶을 때는 어떤 쿼리를 작성해야되나요?
- 미해결다양한 사례로 익히는 SQL 데이터 분석
쿼리 질문
안녕하세요, 도움을 받고자 글 올립니다.97년 이후 nw데이터의 '국가/ 기준월 / 대표제품명 / 구매고객수 / 동시구매 고객 수 / 구매 횟수 / 동시구매 횟수 / 동시구매율' 을 구해보았는데 결과가 나오긴 하는데 맞는지 알 수가 없어서 코드리뷰 부탁드립니다. 더불어 더 좋은 코드가 있을지 여쭙습니다.새해 복 많이 받으세요 with uu as (select customer_id, product_id, order_id, product_name, order_date, ship_addressfrom(select c.product_id, c.product_name, a.amount, b.order_date, b.ship_address , b.customer_id, b.order_idfrom order_items a join orders b on a.order_id = b.order_idjoin products c on a.product_id = c.product_idwhere extract(year from b.order_date) >= 1997) tt), xx as (select ww.customer_id, ww.product_id as prd_01, vv.product_id as prd_02, ww.order_date, ww.ship_addressfrom uu ww join uu vv on ww.customer_id = vv.customer_id), temp_01 as (select customer_id, prd_01, prd_02, extract(year from order_date) as year_ord, extract(month from order_date) as month_ord, ship_address as countryfrom xxwhere prd_01 != prd_02group by 1,2,3,4,5,6order by 1,2,3,4,5,6)---------------구매자 id, 대표제품 id, 동시구매제품 id, 년, 월, 국가, temp_03 as (select prd_01, prd_02, count(*) as cnt_prd_prdfrom temp_01group by 1,2order by 1, 3 desc) -----------------대표제품 id, 동시구매제품 id, 동시구매 횟수, temp_04 as (select distinct product_id, count(customer_id) as cnt_prdfrom order_items oi join orders o on oi.order_id = o.order_idgroup by 1order by 1)-------------------- 대표제품 id, 구매고객수, temp_05 as (select prd_01, prd_02, count(customer_id) as cnt_prd_customerfrom temp_01group by 1,2order by 1,3)-------- 동시구매 고객 수, temp_06 as (select customer_id, count(order_id) as cnt_customerfrom ordersgroup by 1)------ 구매횟수, temp_07 as (select distinct t5.prd_01, t5.prd_02, cnt_prd_customer as 동시구매고객수, sum(cnt_customer) as 구매횟수, cnt_prd_prd as 동시구매횟수, cnt_prd_prd/sum(cnt_customer) as 동시구매율from temp_01 t1 join temp_05 t5 on t5.prd_01 = t1.prd_01 and t5.prd_02 = t1.prd_02join temp_06 t6 on t1.customer_id = t6.customer_idjoin temp_03 t3 on t1.prd_01 = t3.prd_01 and t1.prd_02 = t3.prd_02group by 1,2,3,5order by 1,5 desc) ---/ 동시구매 고객 수 / 구매 횟수 / 동시구매 횟수 / 동시구매율, temp_08 as (select distinct country, year_ord , month_ord , prd_01, cnt_prd as 구매고객수from temp_01 t1 join temp_04 t4 on t1.prd_01 = t4.product_idorder by 1,2,3,4)---국가/ 기준월 / 대표제품명 / 구매고객수select distinct t8.*, prd_02, 동시구매고객수, 구매횟수, 동시구매횟수, 동시구매율from temp_08 t8 join temp_07 t7 on t8.prd_01 = t7.prd_01;
- 해결됨다양한 사례로 익히는 SQL 데이터 분석
복원 관련 질문
안녕하세요,설치 관련해서 문의 드릴려고 합니다.맥북m1 유저인데 공유해주신 backup 파일을 업로드 하려고 하는데 아래 사진과 같이 'start' 버튼이 활성화 되지 않아서 문의 드립니다. 감사합니다.
- 미해결다양한 사례로 익히는 SQL 데이터 분석
효율적인 쿼리
안녕하세요 선생님, nw 데이터로 자체적으로 문제를 만들어 풀어보았는데해당 쿼리가 맞는지, 더 효율적인 쿼리가 있는지 여쭤봅니다. 항상 감사합니다.---- 개인별로 가장 많이 산 상품과 그 상품을 샀을 떄 동시구매한 상품 top 1with temp_01 as (select a.order_id, a.line_prod_seq, a.product_id, a.amount, b.customer_id, c.product_namefrom order_items ajoin orders b on a.order_id = b.order_idjoin products c on a.product_id = c.product_id ), kk as (select d.customer_id, d.order_id, d.product_id, d.product_name, d.amount, d.line_prod_seqfrom temp_01 d), aa as (select d.customer_id, d.product_id as prod_01, kk.product_id as prod_02from temp_01 d join kk on d.customer_id = kk.customer_idwhere d.product_id != kk.product_id), bb as (select aa.customer_id, aa.prod_01, aa.prod_02, count(*) prd_numfrom aagroup by 1,2,3order by 1,2,4 desc) , cc as (select customer_id, prod_01, prod_02, max(prd_num) max_numfrom bbgroup by 1,2,3)select *from ccwhere prod_01 != prod_02 and max_num != 1
- 미해결다양한 사례로 익히는 SQL 데이터 분석
과거 30일간 페이지별 조회수와 순페이지 조회수 구하기
withtemp_01 as ( select a.sess_id, a.page_path, hit_seq, hit_time , lead(hit_time) over (partition by a.sess_id order by hit_seq) as next_hit_time , row_number() over (partition by a.sess_id, page_path order by hit_seq) as rnum from ga.ga_sess_hits a join ga_sess b on a.sess_id = b.sess_id where visit_stime >= (:current_date - interval '30 days') and visit_stime < :current_date and a.hit_type = 'PAGE')select page_path,count(*) as page_cnt , count(case when rnum = 1 then '1' else null end) as unique_page_cnt , round(avg(next_hit_time - hit_time)/1000.0, 2) as avg_elapsed_secfrom temp_01group by page_path order by 2 desc;>강의에서 설명한 위의 코드를 아래의 코드로 사용해도 괜찮을까요?순페이지 조회수 구할 때 row_number로 안하고 distinct sess_id로 해도 괜찮을까요? withtemp_01 as ( select a.sess_id, a.page_path, hit_seq, hit_time , lead(hit_time) over (partition by a.sess_id order by hit_seq) as next_hit_time from ga.ga_sess_hits a join ga_sess b on a.sess_id = b.sess_id where visit_stime >= (:current_date - interval '30 days') and visit_stime < :current_date and a.hit_type = 'PAGE')select page_path,count(*) as page_cnt , count( distinct sess_id) as unique_page_cnt , round(avg(next_hit_time - hit_time)/1000.0, 2) as avg_elapsed_secfrom temp_01group by page_path order by 2 desc;