Daily, Weekly and Monthly filter in same query

How can I get a user count by daily, weekly and monthly time frame and using more variables

eg.
I need user count (daily/weekly/month) by channel, campaign, adds

Can I compute entire thing in a single query?

You could do something like this in SQL:

SUM(CASE WHEN date BETWEEN {{week_filter_start}} AND {{week_filter_end}} THEN 1 ELSE 0 END) as weekly_count

Postgres 9.4+ lets you ...FILTER(WHERE...:

SELECT
  COUNT(*) AS unfiltered,
  COUNT(*) FILTER (WHERE i < 5) AS filtered
FROM generate_series(1,10) AS s(i);

Searching on Stack Overflow or Google might yield faster results for questions like this:

For instance the first result in that Stack Overflow search appears to offer the same solution as my first suggestion:

1 Like