I've a simple but large table in an SQL database which has four fields:
id (int PK)
time (unix timestamp, not null)
value (double, not null)
ID_fk (integer foreign key)
Data is recorded every minute, but at a seemingly random second for subsets of sensors, each sensor has a foreign key value though.
My question is this:
- I need to write a query that will tell me when, over all two minute intervals in the dataset, a series of sensors have a value greater than 0.9.
I was thinking for trying to create a temporary table and do it that way, simplifying the time by only storing it at minute resolution?
Any advice would be greatly received.
Best Answer
You could try using a CTE recursive function that generates a time series.
There is an answer on SO that shows how to do it: