There is a table of the form, size ~ 10 tons of records: timestamp │ value ─────────────────────────┼────────── 2017-01-17T10:47:13.757Z │ 12.34 2017-01-17T10:48:23.261Z │ 15.65 2017-01-17T10:51:13.254Z │ 17.56 There is a separate list of times Z, ~ 50 points. You need to get a table of the form z[i],t0,v0,t1,v1 where z [i] is a point from the list, data from the table, with a maximum time not exceeding z [i], - with a minimum time but longer z [i] . Those find the values that precede and immediately follow the desired point. If the time before or after does not exist, then let it be t0, v0 or t1, v1 be NULL.
Question 1. Where is the best place to keep data for table Z. For example, you can start a temporary table for the duration of the calculation, and then destroy it.
Question 2. How to write a SQL query that make the necessary sample.
PS Base sqlite, everything works under node.js The task is this: You need to build a temperature graph. The data from the sensors are added to the table at any time. The difference between the records can be from 10 seconds to 30 minutes. It would be desirable to receive average data.