Data Analysis

MODE PROJECT 'A Drop In Engagement' _SQL Query_#WAU

Genie Lee 2022. 3. 3. 18:58
728x90
반응형

 


아래 차트의 쿼리문을 살펴 봅시다.

 

현업에서 듣는 query 작성 팁

| Query 1 1

 

 

Weekly Active Users_Query 1

| Query 1 해설 

# DATE_TRUNK함수를 쓰면, week 별로 그룹을 만들어 준다.
# occurred_at에 있는 날짜를 week별로 그룹을 지을거라는 의미.
# week라고 alias 할거라는 의미
SELECT DATE_TRUNK('week', e.occured_at) AS week
 ,COUNT(DISTINCT user_id) AS weekly_active_users    # 한명이 여러 번 engagemenr를 할 수 있으니까, user_id로 DISTINCT를 해줌.
FROM tutorial.yammer_events e
# ‘WHERE ~에 있으면서,AND이고, AND이다. 라는 조건 명시'
WHERE e.occurred_at BETWEEN '2014-04-28 00:00:00' AND '2014-08-25 23:59:59‘ # 실제 현업 데이터는 몇년간의 자료가 한번에 들어있을것이므로, 꼭 WHERE로 기간을 정해주는 것을 제일 먼저 해야 한다.
AND e.event_type = 'engagement‘
# 주차별(week)로 group by를 해줄 거기 때문에, week 열이 제일 처음으로 나온다. 
GROUP BY week
# group 정렬은 오름차순으로
ORDER BY week

    Run Now    

query1 result

 


| Query 2

 

Weekly Active Users_Query 2

 

    Run Now    

query2 result


Query 2 가 안 좋은 이유는?

# 설명을 보시기 전에 어떤 부분이 수정이 필요한지 생각해 보시기 바랍니다:)

 


Yammer 프로젝트 튜토리얼 링크

https://mode.com/sql-tutorial/a-drop-in-user-engagement/

 

Investigating a Drop in User Engagement | SQL Analytics Training - Mode

In this lesson we'll cover: Before starting, be sure to read the overview to learn a bit about Yammer as a company. Yammer's Analysts are responsible for triaging product and business problems as they come up. In many cases, these problems surface through

mode.com

 

728x90
반응형