I would like to calculate the total unique accounts in a 30 day range. The engine I am using on MySQL (InfiniDB) seems to only support joining tables on equality conditions.
My table looks like this:
sessions (date_id, account_id) =
{ '2013-07-07', 5
'2013-07-07', 5
'2013-07-07', 1
'2013-07-08', 3
'2013-07-09', 3
}
My current query looks like this:
SELECT
date_id, (
SELECT COUNT(DISTINCT account_id)
FROM sessions t2
WHERE t2.date_id BETWEEN DATE_SUB(t1.date_id, INTERVAL 30 DAY) AND t1.date_id
) cnt
FROM sessions t1
GROUP BY date_id
Only equi-joins are supported so the BETWEEN
operator does not work to join the tables.
Any help is greatly appreciated :)