I have a program that checks status of Computers in a network by PING each minutes. Each time it will insert a new row to DB as follows (I'm using postgresql)
id_status status checking_time(timestamp) id_device(int) 1 OK '2017-01-01 00:00:00' 1 2 OK '2017-01-01 00:00:00' 2 3 OK '2017-01-01 00:00:00' 3 4 Failed '2017-01-01 00:01:00' 1 5 OK '2017-01-01 00:01:00' 2 6 OK '2017-01-01 00:01:00' 3 7 Failed '2017-01-01 00:02:00' 1 8 OK '2017-01-01 00:02:00' 2 9 OK '2017-01-01 00:02:00' 3 10 Failed '2017-01-01 00:03:00' 1 11 OK '2017-01-01 00:03:00' 2 12 OK '2017-01-01 00:03:00' 3 13 OK '2017-01-01 00:04:00' 1 14 OK '2017-01-01 00:04:00' 2 15 OK '2017-01-01 00:04:00' 3 I want result to be as follows
status from_time(timestamp) to_time(timestamp) id_device(int) OK '2017-01-01 00:00:00' '2017-01-01 00:01:00' 1 Failed '2017-01-01 00:01:00' '2017-01-01 00:04:00' 1 OK '2017-01-01 00:04:00' NOW 1 OK '2017-01-01 00:00:00' NOW 2 OK '2017-01-01 00:00:00' NOW 3 How can I get this output?.