I’m looking select every X point from a table that holds a time-stamp , value pair. For example:
CREATE TABLE data (
value double NOT NULL,
timestamp datetime NOT NULL,
PRIMARY KEY (timestamp),
) ENGINE=InnoDB DEFAULT CHARSET=latin1
If I run:
SELECT * FROM data where timestamp < a and timestamp > b order by timestamp desc
I can receive all of the values and filter them in code, however is there a better way to do this (hopefully directly in sql). We can safely assume that data points will occur every X minutes.
Thanks,
How about taking the difference between the timestamp and your zero-reference point in minutes, and checking if it’s at the interval? Assuming your reference point is
b:Of course you will not be able to use an index with this but at least you can avoid returning all the data.