Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Counting occurences of ranges within anothe range

Author  Topic 

Knud
Starting Member

2 Posts

Posted - 2012-05-07 : 04:58:09

Hi,

I hope you can help me out with the following problem. I have a list of ranges in my database. I need to know the maximum of overlapping ranges.

In the example below I want to know how many ranges there are within 'request range' at the same time.
The result should be 2 as 'DB range1' and 'DB range2' are the maximum number of ranges overlapping at the same time.

..................REQUEST RANGE............................
....<-------------------------------------------->.........
..DB RANGE1................................................
<----------->..............................................
.........DB RANGE2.........................................
.......<----------->.......................................
...........................................DB RANGE3.......
.........................................<----------->.....
....................DB RANGE4..............................
..................<----------->............................

I hope my question make sense and that someone can help me?.

PS. I had to replace spaces with .

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-07 : 05:02:50
How do you count as 2 ?

Range1 overlap with Range2 as 1
Range2 overlap with Range4 as 1 ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-07 : 05:09:34
See

http://www.sqlmag.com/article/tsql3/calculating-concurrent-sessions-part-1
http://www.sqlmag.com/article/tsql3/calculating-concurrent-sessions-part-2
http://www.sqlmag.com/article/tsql3/calculating-concurrent-sessions-part-3


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

Knud
Starting Member

2 Posts

Posted - 2012-05-07 : 05:15:04
khtan:

Because the maximum number of overlapping ranges within 'request range' is 2:

DBRange1 and DBRange2
or
DBRange2 and DBRange4

But the point is that at no time are there anymore than two ranges overlapping eachother.

SwePeso:
I have looked at your links and I am not sure I can see exactly how it applies to my specific problem.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-05-07 : 05:23:33
quote:
Originally posted by Knud
I have looked at your links and I am not sure I can see exactly how it applies to my specific problem.



Wow. you are a fast reader. I am still on Part 1


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2012-05-07 : 06:11:13
The articles are about how to calculate the maximum concurrent sessions, which is exactly your task.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -