GROUP by time looking "backwards" from a specific timestamp

Unfortunately there isn’t a way to look at time relative to the last timestamp with influxql.
I might suggest using another processing tool like quix or bytewax.