AndyP
AndyP

Reputation: 607

How to get data for past X days using timestamp column?

I have a below query which gives me data for past 12 hour. Instead of that I wanted to get data for past X days which should be configurable if possible? Is there any way to do it?

SELECT processId,
 houroftheday,
 minuteofhour,
 listagg(clientId, ',') within group (order by minuteofhour) as clientIds,
 count(*) as psg
 FROM data.process
 where kite = 'BULLS'
 and code is null
 and timestampinepochsecond > date_part(epoch, sysdate) - 3600 * 12
 group by 1, 2, 3

How can I use timestampinepochsecond column to get data for past X days?

Upvotes: 0

Views: 34

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271171

The passed N days would be:

 timestampinepochsecond > date_part(epoch, sysdate) - N*24*60*60

Upvotes: 1

Related Questions