I have table with the following column:
[name_of_pos] varchar,
[date_from] datetime,
[date_to] datetime
Below is my sample data:
name_of_pos date_from date_to
----------------------------------------------------------------
Asystent 2015-08-26 08:57:49.000 2015-09-04 08:57:49.000
Biuro 2015-09-01 08:53:32.000 2015-09-01 08:53:32.000
Biuro 2015-09-02 09:00:41.000 2015-09-02 09:00:41.000
Biuro 2015-09-03 11:46:03.000 2015-09-03 11:46:03.000
Biuro 2015-09-10 09:02:11.000 2015-09-15 09:02:11.000
Koordynator 2015-09-01 09:04:06.000 2015-09-01 09:04:06.000
Projektant 2015-08-31 08:59:46.000 2015-09-01 08:59:46.000
Projektant 2015-09-02 08:00:54.000 2015-09-02 08:00:54.000
Projektant 2015-09-14 12:34:50.000 2015-09-14 12:34:50.000
What I want to return is the date range (min of date_from
to max of date_to
) for each name_of_pos
, but only where the date values are continuous (the time part is not important and can be ignored in result).
The desired output would be:
name_of_pos date_from date_to
------------------------------------
Asystent 2015-08-26 2015-09-04
Biuro 2015-09-01 2015-09-03
Biuro 2015-09-10 2015-09-15
Koordynator 2015-09-01 2015-09-01
Projektant 2015-08-31 2015-09-02
Projektant 2015-09-14 2015-09-14
I tried a solution using something similar to this question:
How do I group on continuous ranges
But had no luck as I have two datetime columns.