Skip to content

Instantly share code, notes, and snippets.

@ks--ks
Created August 2, 2018 18:10
Show Gist options
  • Select an option

  • Save ks--ks/fa0e54052cad3a2584f50006f730a63f to your computer and use it in GitHub Desktop.

Select an option

Save ks--ks/fa0e54052cad3a2584f50006f730a63f to your computer and use it in GitHub Desktop.
action_view as
(
SELECT created_at::date AS viewdate,
COUNT(av.userid) AS act_v,
CASE when av.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN av.state ELSE 'other' END AS state,
CASE WHEN av.current_medium IN ('source1', 'source2', 'source3') THEN av.current_medium ELSE 'other' END AS source,
lower('id-' || av.created_at::date ||
'-' || CASE when av.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN av.state ELSE 'other' END ||
'-' || CASE WHEN av.current_medium IN ('source1', 'source2', 'source3') THEN av.current_medium ELSE 'other' END
) AS idp
FROM act_view av
WHERE created_at::date > getdate()::date - 60
AND created_at::date <= getdate()::date - 1
GROUP BY viewdate, state, source
ORDER BY viewdate, state, source
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment