How would I go about intervals and matching closest value with n1ql?
file.zip (7.9 KB)
I have several files like this one, one for each day. What I want is to select a initial interval like:
BETWEEN “2015-01-02T10:00:00” AND “2015-06-04T06:02:00” END
which I got help with (thank you, vsr1 )
SELECT d.panelid, d.sensorid, ARRAY_FLATTEN(ARRAY_AGG(qdata),2) AS data
FROM data
d
LET qdata = ARRAY el FOR el IN d.data WHEN el.timestamp BETWEEN “2015-01-02T10:00:00” AND “2015-06-04T06:02:00” END
WHERE panelid=“a-si” and sensorid=“voc” AND ARRAY_LENGTH(qdata) > 0
GROUP BY d.panelid, d.sensorid;
This query will give me all objects between the two dates, but let’s say I want only one object for each hour from “2015-01-02T10:00:00” to “2015-06-04T06:02:00”. The interval will be given in this format: HH:MM. Managing this is my first problem, but I also need some way to match the closest timestamp (the objects contain timestamps), ie if I want the object closest to 11:00 which isn’t necessarily exactly 11:00 (could be 10:58 f.eks)