I have a database with trending data, the structure is like this:
[Timestamp, System_State]
2012-01-01 00:00:00, 1
2012-01-01 00:01:00, 1
2012-01-01 00:02:00, 0
2012-01-01 00:03:00, 1
2012-01-01 00:04:00, 1
2012-01-01 00:05:00, 0
...
Now I need to write a SQL query to know when the system starts (system_state changes from 0 to 1) and when it stops (state changes from 1 to 0). Do I have any options beside using cursor?
Thanks.
How about something like this (this is T-SQL, i.e. SQL Server, but may be applicable to MySql too)
–alteratively:
–or