Considering the following table:
someId INTEGER #PK
ageStart TINYINT(3)
ageEnd TINYINT(3)
dateBegin INTEGER
dateEnd INTEGER
Where dateBegin
and dateEnd
are dates represented as days since 1800-12-28
...
And considering some sample data:
someId | ageStart | ageEnd | dateStart | dateEnd
------------------------------------------------
203 | 16 | 25 | 76533 | 76539 \
506 | 16 | 25 | 76540 | 76546 adjacent rows
384 | 16 | 25 | 76547 | 76553 /
342 | 16 | 25 | 76563 | 76569 \
545 | 16 | 25 | 76570 | 76576 adjacent rows
764 | 16 | 25 | 76577 | 76583 /
(There would be arbitrary rows mixed in off course, I just want to illustrate 2 relevant rowsets)
Is it possible to find adjacent rows for a given age category (ageStart to ageEnd) without a stored procedure? The criteria for adjacency is: dateStart
is 1 day after dateEnd
of the previous found row.
For instance, given the above sample data, if I were to query it with the following parameters:
ageStart = 16
ageEnd = 25
dateStart = 76533
I would like it to return me the rows 1, 2 and 3 of the sample data, since their dates are adjacent (dayStart is next day of previous row's dateEnd).
ageStart = 16
ageEnd = 25
dateStart = 76563
...would give me rows 4, 5 and 6 of the sample data