Created
August 2, 2018 18:05
-
-
Save ks--ks/401e529f7b3652a8ee857f47fb29e9cc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| WITH actions AS | |
| ( | |
| SELECT ca.created_at::date as actdate, | |
| COUNT(*) AS act, | |
| CASE when ca.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN ca.state ELSE 'other' END AS state, | |
| CASE WHEN ca.current_medium IN ('source1', 'source2', 'source3') THEN ca.current_medium ELSE 'other' END AS source, | |
| lower('id-' || ca.created_at::date || | |
| '-' || CASE when ca.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN ca.state ELSE 'other' END || | |
| '-' || CASE WHEN ca.current_medium IN ('source1', 'source2', 'source3') THEN ca.current_medium ELSE 'other' END | |
| ) AS id | |
| FROM events e | |
| JOIN create_action ca ON ca.action_id = e.id | |
| WHERE e.type > 0 | |
| AND ca.created_at::date > getdate()::date - 60 | |
| AND ca.created_at::date <= getdate()::date - 1 | |
| GROUP BY actdate, state, source | |
| ORDER BY actdate, state, source | |
| ), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment