mysql query for elapsed time per day

89 Views Asked by At

I have such this table as below and I trying to calculate the elapsed time for which the value "relay" is to 1 per day by creating a view.

id, date, time, dateandtime,timestamp,sensor,temperature,humidity,status
xx   15/03/2018 11:39:00    15/03/2018 11:39:00.0   15/03/2018 11:39    sensor1 23  41  0
xx   15/03/2018 11:40:00    15/03/2018 11:40:00.0   15/03/2018 11:39    sensor2 23  41  1

Here is the query that I come with, however the output is not as except for the past or previous day...

select date,time,TIMESTAMPDIFF(MINUTE,MAX(Date), timestamp) as minutes FROM temperaturedata where relay = 1 group by date

Here is the results:

date time minutes
2018-03-15 11:39:00 699 
2018-03-16 11:01:00 661

Some clarifications, I am trying to get how long per day and hour the status has been set to 1.

something like:

date, starttime, endtime, minutes; 

As starttime would be when the first of instance to 1 appears and endtime the last time, minutes the total amount of minutes for which the status was to 1.

hope it make a bit more sense. :)

Any guidance would be more than welcome.

THanks. J.

0

There are 0 best solutions below