J
J
j3qq4h7h2v2hch4m3hk86m8vw2015-12-03 00:48:03
SQL
j3qq4h7h2v2hch4m3hk86m8vw, 2015-12-03 00:48:03

How to count the number of continuous date intervals given by a set of date intervals that include the entire given interval?

The crux of the matter is as follows.
A table of date intervals is specified, for example

Номер | ДатНач  | ДатКнц
1       01.01.15 01.02.15
2       15.01.15 15.03.15

sql-query should return the number of continuous intervals (which can be made up of these intervals) that entirely include the given interval BackStart-BackEnd

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
repeat, 2015-12-03
@repeat

SELECT COUNT(*) FROM table WHERE setpoint >= dateset AND setpoint <= dateset

J
j3qq4h7h2v2hch4m3hk86m8vw, 2015-12-03
@j3qq4h7h2v2hch4m3hk86m8vw

I'll try to clarify the question, for the same example

Номер | ДатНач  | ДатКнц
1       01.01.15 01.02.15
2       15.01.15 15.03.15

Let's take, for example, SetStart = 01/10/15 and SetStart = 02/15/15. The query should return the quantity 1.
BackStart-BackEnd is not completely included in any range from the table, but if you superimpose all the ranges from the table on top of each other (two in this case), you get one continuous one , in which BackStart-BackEnd is completely included.
If, for example, SetStart = 01/10/15 and SetEnd = 03/16/15, then the query will return 0.
And if, for example, SetStart = 01/15/15 and SetEnd = 01/30/15, then the query will return 2, since it is completely included in both ranges from the table

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question