So, I have a query that uses GETDATE() in `WHERE` and `HAVING` clauses:

```
SELECT GETDATE(), COUNT(*) FROM (
  SELECT 1 FROM events
  WHERE (event_time > (GETDATE() - interval '25 hours'))
  GROUP BY id
  HAVING MAX(event_time) BETWEEN (GETDATE() - interval '25 hours') AND (GETDATE() - interval '24 hours')
)

```

I'm basically trying to find the number of unique `id`s that have their latest `event_time` between 25 and 24 hours ago with respect to the current time.

**The problem:** I have another table `query_dts` which contains one column containing timestamps. Instead of running the above query on the current time, using `GETDATE()`, I need to run in on the timestamp of every entry of the `query_dts` table. Any ideas?

Note: I'm not really storing `query_dts` anywhere. I've created it like this:

```
WITH query_dts AS (
  SELECT (
    DATEADD(hour,-(row_number() over (order by true)), getdate())
  ) as n
  FROM events LIMIT 48
),

```

which I got from [here](https://www.periscopedata.com/blog/generate-series-in-redshift-and-mysql.html)