I am trying to get logging data from a table. Where I select a timespan (“maandag” till “vrijdag”). This gets the results I want but now I get the question to only show 3 measurements per day.
The first one being the first after 8 o clock
The second one being the first one after 14:00 o closk
and the third the first one after 20:00 o clock
The problem I have is that the time of the measurements is not constant. So using a regexp to select a part of the day doesn’t work.
With the query below I sometimes also get 2 or 4 or even more results per day. This is because basicly the time between measurements is 2 hours but this is not constant neither is it so that measurements the next day are on the same time.
Is it possible to group by a part of the day?
Or what other solution is there?
data:
id datumTijd ph tbc temperatuur vbc gbc
1 2012-10-03 14:59:19 7.30.08 24.91 0.02 0
1 2012-10-03 16:47:38 7.33.07 22.15 0.12 0
3 2012-10-03 17:03:06 7.31.09 23.23 0.05 0
query:
SELECT N.name, D.datumTijd, ROUND(D.gbc,2), ROUND(D.vbc,2), ROUND(D.tbc,2),ROUND(D.ph,2), ROUND(D.temperatuur,1)
FROM METING.Name N, METING.Data D
Where D.datumTijd BETWEEN "'+maandag+' 00:00:00" AND "'+vrijdag+' 23:59:59"
AND N.id = D.id AND D.datumTijd
AND D.datumTijd REGEXP "0[78]:..:..|1[34]:..:..|2[12]:..:.."';
ORDER BY N.name, D.datumTijd
You could do something like this to group results into the 3 different periods. You could then use aggregate functions (SUM, MIN, MAX) on your measures.