Your version is [very antiquated and insecure. For reference 8.2 was last supported in 2011. It was released in 2006.](https://www.postgresql.org/support/versioning/) It lacks * tstz ranges * window functions * lateral joins Moreover, we can't easily configure your setup to test our queries. Upgrade your version PostgreSQL; if you find that difficult to do, consider seeking out a consultant. I think what you want is something like SELECT member_id, t2.date, count(*) FROM t AS t1 CROSS JOIN t AS t2 ON ( member_id ) WHERE t1.date_date BETWEEN t2.date AND t2.date_date + '7 days GROUP BY member_id, t2.date HAVING count(*) >= 7; But I can't test it and you didn't provide `CREATE TABLE` or `INSERT` statements.