-
-
Save codecademydev/21b18cbe26b76999fa91075a3b8e18e1 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--My query for question 3 | |
WITH first_touch AS ( | |
SELECT user_id, | |
MIN(timestamp) AS first_touch_at | |
FROM page_visits | |
GROUP BY user_id) | |
SELECT pv.utm_campaign | |
, pv.utm_source | |
, COUNT(*) AS ft_count | |
FROM first_touch ft | |
JOIN page_visits pv | |
ON ft.user_id = pv.user_id | |
AND ft.first_touch_at = pv.timestamp | |
GROUP BY pv.utm_campaign | |
ORDER BY ft_count DESC; | |
--hint/recommended query for question 3 | |
WITH first_touch AS ( | |
SELECT user_id, | |
MIN(timestamp) as first_touch_at | |
FROM page_visits | |
GROUP BY user_id) | |
, ft_attr AS ( | |
SELECT ft.user_id | |
, ft.first_touch_at | |
, pv.utm_source | |
, pv.utm_campaign | |
FROM first_touch ft | |
JOIN page_visits pv | |
ON ft.user_id = pv.user_id | |
AND ft.first_touch_at = pv.timestamp) | |
SELECT ft_attr.utm_campaign | |
, ft_attr.utm_source | |
, COUNT(*) | |
FROM ft_attr | |
GROUP BY 1, 2 | |
ORDER BY 3 DESC; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment