I have a data which has two time based columns - date, hour (other columns are present). My aim is to read data for a particular time period.
Data:
date hour
22-06-20 0
22-06-20 1
.. ..
23-06-20 23
Aim: Read data between 22-06-20 4th hour to 23-06-20 4th hour.
Query I have is:
select date, hour from mytable where
date >= date("22-06-20")
and hour >= 4;
The above would give me data from 22-06-20 4th hour to 23-06-20 23rd hour. But how to stop it with 4th hour of 23-06-20.
I have shown a hard coded example above, however what I am trying is in real time as my table gets updated hourly.
select date, hour from mytable where
date >= date(current_timestamp - interval '25' hour)
and hour >= hour(current_timestamp - interval '25' hour)
Why I am doing -25 hours is I want last 24 hours data excluding the last hour i.e say now is 10th hour of 23-06-20. I want data from 22-06-20 9th to 23-06-20 9th. Trying to solve the above query should help me do this as well.