Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

looking for a query to find first/last dates in overlapping dates...

$
0
0

Hi,

I'm looking for a query to find the first dates and last dates in a table conaining overlapping dates.

I have a subscription table which has for each Customer start and end date for different subscriptions.

I want to know the different ranges of date where there is subscriptions active.

so if the table has this:

CustID, Start date, end date

1, 2008-01-01, 2012-06-06

1 ,2009-01-01, 2011-01-01

1, 2011-01-01, 2013-02-02

1, 2013-01-01, 2013-08-08

1, 2014-01-01, 2014-04-04

I want to produce this result:

custid, range start, range end

1, 2008-01-01, 2013-08-08

1, 2014-01-01, 2014-04-04

the first row is the range identified from the 4 rows in my subscription table.

thanks :)


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>