This is my initial table, (the dates are in DD/MM/YY format)
ID DAY TYPE_ID TYPE NUM START_DATE END_DATE
---- --------- ------- ---- ---- --------- ---------
4241 15/09/15 2 1 66 01/01/00 31/12/99
4241 16/09/15 2 1 66 01/01/00 31/12/99
4241 17/09/15 9 1 59 17/09/15 18/09/15
4241 18/09/15 9 1 59 17/09/15 18/09/15
4241 19/09/15 2 1 66 01/01/00 31/12/99
4241 20/09/15 2 1 66 01/01/00 31/12/99
4241 15/09/15 3 2 63 01/01/00 31/12/99
4241 16/09/15 8 2 159 16/09/15 17/09/15
4241 17/09/15 8 2 159 16/09/15 17/09/15
4241 18/09/15 3 2 63 01/01/00 31/12/99
4241 19/09/15 3 2 63 01/01/00 31/12/99
4241 20/09/15 3 2 63 01/01/00 31/12/99
2134 15/09/15 2 1 66 01/01/00 31/12/99
2134 16/09/15 2 1 66 01/01/00 31/12/99
2134 17/09/15 9 1 59 17/09/15 18/09/15
2134 18/09/15 9 1 59 17/09/15 18/09/15
2134 19/09/15 2 1 66 01/01/00 31/12/99
2134 20/09/15 2 1 66 01/01/00 31/12/99
2134 15/09/15 3 2 63 01/01/00 31/12/99
2134 16/09/15 8 2 159 16/09/15 17/09/15
2134 17/09/15 8 2 159 16/09/15 17/09/15
2134 18/09/15 3 2 63 01/01/00 31/12/99
2134 19/09/15 3 2 63 01/01/00 31/12/99
2134 20/09/15 3 2 63 01/01/00 31/12/99
And I've to create groups with initial DAY and end DAY for the same ID, and TYPE.
I don't want to group by day, I need to create a group every time my TYPE_ID changes, based on the initial order (ID, TYPE, DAY ASC)
This is the result that I want to achieve:
ID DAY_INI DAY_END TYPE_ID TYPE NUM START_DATE END_DATE
---- --------- --------- ------- ---- ---- --------- ---------
4241 15/09/15 16/09/15 2 1 66 01/01/00 31/12/99
4241 17/09/15 18/09/15 9 1 59 17/09/15 18/09/15
4241 19/09/15 20/09/15 2 1 66 01/01/00 31/12/99
4241 15/09/15 15/09/15 3 2 63 01/01/00 31/12/99
4241 16/09/15 17/09/15 8 2 159 16/09/15 17/09/15
4241 18/09/15 20/09/15 3 2 63 01/01/00 31/12/99
2134 15/09/15 16/09/15 2 1 66 01/01/00 31/12/99
2134 17/09/15 18/09/15 9 1 59 17/09/15 18/09/15
2134 19/09/15 20/09/15 2 1 66 01/01/00 31/12/99
2134 15/09/15 15/09/15 3 2 63 01/01/00 31/12/99
2134 16/09/15 17/09/15 8 2 159 16/09/15 17/09/15
2134 18/09/15 20/09/15 3 2 63 01/01/00 31/12/99
Could you please give any clue about how to do it??, thanks!