I have repeat rows in a table with several dates:
ID STATE DATE
----------------------------
id01 connected 2015-04-04
id01 connected 2015-04-05
id01 connected 2015-04-08
id01 disconect 2015-04-11
id01 disconect 2015-04-12
id01 connected 2015-04-13
I want a query with "start date" and "end date", with this result:
ID STATE START DATE END DATE
----------------------------------------
id01 connected 2015-04-04 2015-04-10
id01 disconect 2015-04-11 2015-04-12
id01 connected 2015-04-13 XXXXXXXXXX
The last "end date" it's not important (last value, null, now()...)
The most important is detect date of change (in this example no row for 2015-04-10, and the same state happends in 2015-04-13).
Posible solution? (not valid)
SELECT ID, STATE, MIN(date), MAX(date)
FROM TABLE
GROUP BY ID, STATE;
Isn't valid because merge intervals:
ID STATE START DATE END DATE
----------------------------------------
id01 connected 2015-04-04 XXXXXXXXXX
id01 disconect 2015-04-11 2015-04-12
Query has run in Impala (similar SQL92)