MySQL Forums
Forum List  »  Newbie

Query for collecting time
Posted by: Frank Kirschner
Date: April 29, 2016 12:12AM

Hi,
A table has two columns: stamp (DATETIME) and status (TINYINT) and looks like:
stamp___________________status
2016-03-24 11:50:58_____2
2016-03-24 11:51:00_____1
2016-03-24 11:52:50_____2
2016-03-24 11:52:52_____1
2016-03-24 11:54:20_____2
2016-03-24 11:54:45_____1
2016-03-24 14:28:09_____2
2016-03-24 14:31:09_____1
2016-03-24 14:38:50_____2
2016-03-24 14:38:55_____1
2016-03-24 15:55:58_____2
2016-03-24 15:59:09_____1
2016-03-24 16:36:05_____2
2016-03-24 16:41:27_____1
2016-03-24 16:43:36_____2

The meaning of status is: 1 = machine off, 2 = machine on. My goal is to find out how long was the machine on per day, that is the difference between a row where the status of the previous was 1 and switched to 2. Is there a statement what can do this, compare a previous line with the next and so on?

thanks,
best regards
Frank

Options: ReplyQuote


Subject
Written By
Posted
Query for collecting time
April 29, 2016 12:12AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.