I am newbie to postgresql and still getting my head around. I have used windows function etc. till date and yes I can make some sense.
I have got the following data set:
I need to find those customers whose amount > 2 for 4 minutes in a rolling fashion, considering the data for a day. By that I mean in the given data set, customer 1 is one such as it has got amount > 2 at 16:01,16:02,16:03,16:04 and then at 16:02,16:03,16:04, 16:05. If there is any such single occurrence, the customer needs to be selected. Customer 2 doesn't have so. Wondering what's the best approach to do this?
Any help will be much appreciated.
Regards,
Best Answer
Schematically:
or
If time roll is to be "full", use 1st query adding relevant restriction:
or
fiddle