I'm trying to get the total number of users who transacted last month and have come back so far this month.
At the moment, my code works with the exception of not being able to sum up the count of unique user IDs. Here's what I have
SELECT * from
(
SELECT tx_date, count(distinct user_id)
from (
SELECT p.user_id, date(min(p.timestamp)) tx_date
from purchase p
where date(timestamp) between '2018-04-01' and '2018-04-30'
and user_id in (SELECT * from analytics_march_mau)
group by 1) b
group by 1) t1
JOIN (
select distinct date(timestamp) dates
from purchase
where date(timestamp) between '2018-04-01' and '2018-04-30') a
on a.dates >= t1.tx_date
group by 1
Which gives me the below results
Problem now is that I need to change the viewed data to only return the tx_date and sum of the second column
This should change
SELECT * from
To something like
SELECT dates, SUM(count)
But when I try this I get an error "Unknown column 'count' in 'field list'" I have no idea what that column is called
PS: I got the idea of this query from a friend, if there's an easier way to get this done, I'd be happy to try that instead.