22.07.12 21:26 작성
·
238
1
SELECT DATE_TRUNC('week', e1.occurred_at) AS week
, COUNT(CASE WHEN e1.action = 'sent_weekly_digest' THEN e1.user_id ELSE NULL END) AS weekly_digest_email
, COUNT(CASE WHEN e1.action = 'sent_weekly_digest' THEN e2.user_id ELSE NULL END) AS weekly_digest_email_open
, COUNT(CASE WHEN e1.action = 'sent_weekly_digest' THEN e3.user_id ELSE NULL END) AS weekly_digest_email_clickthrough
FROM tutorial.yammer_emails e1
LEFT JOIN tutorial.yammer_emails e2
ON e2.occurred_at BETWEEN e1.occurred_at AND e1.occurred_at + INTERVAL '5 MINUTE'
AND e2.user_id = e1.user_id
AND e2.action = 'email_open'
LEFT JOIN tutorial.yammer_emails e3
ON e3.occurred_at BETWEEN e1.occurred_at AND e1.occurred_at + INTERVAL '5 MINUTE'
AND e3.user_id = e1.user_id
AND e3.action = 'email_clickthrough'
WHERE occurred_at BETWEEN '2014-06-01 00:00:00' AND '2014-08-31 23:59:59'
AND action IN ('sent_weekly_digest', 'sent_reengagement_email')
GROUP BY week;
야머스 차트로부터의 쿼리말고
강의때 작성해주신 쿼리로
피봇테이블까지 작성해보고 싶은데
자꾸 오류가 나서요
쿼리문 혹시 따로 올려주실 수 있으실까요?