Click here to Skip to main content
15,879,095 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL Server Query Transportation Time Based on Latency and Internet Download Speed Pin
Wendelius1-Apr-11 6:42
mentorWendelius1-Apr-11 6:42 
GeneralRe: SQL Server Query Transportation Time Based on Latency and Internet Download Speed Pin
T21021-Apr-11 16:04
T21021-Apr-11 16:04 
GeneralRe: SQL Server Query Transportation Time Based on Latency and Internet Download Speed Pin
Wendelius1-Apr-11 20:43
mentorWendelius1-Apr-11 20:43 
Questioninvalid parameter value on CreateSubscription Pin
run4ever_771-Apr-11 2:40
run4ever_771-Apr-11 2:40 
QuestionHarmless joke or mean prank Pin
shelbypowell1-Apr-11 1:14
shelbypowell1-Apr-11 1:14 
QuestionSelecting from an XML datatype into a table Pin
Mel Padden31-Mar-11 23:47
Mel Padden31-Mar-11 23:47 
AnswerRe: Selecting from an XML datatype into a table Pin
Mel Padden1-Apr-11 0:01
Mel Padden1-Apr-11 0:01 
QuestionSQL question Pin
loyal ginger31-Mar-11 8:14
loyal ginger31-Mar-11 8:14 
I seem to be incapable of figuring out how to construct a query to achieve a simple thing. I was given a Microsoft Access table that looks like this: (This is just a simplified example)

RoadID      Begin        End
----------------------------
01005       0.0          2.3
01005       2.3          4.2
01005       4.2         10.7
01005      12.5         14.4
01005      14.4         16.9
01002       0.0         13.2
01002      13.2         16.2
01002      16.2         17.8
01002      17.8         21.2
02003       0.0          5.5
02003       7.2         10.2
02003      10.2         16.3
02003      16.3         27.8


Is it possible to make a query to find all the records that have a gap between it and the records before or after it (for each RoadID). The order of the original records should be sorted by RoadID and Begin. For this example, the output should be:

RoadID      Begin        End
----------------------------
01005       4.2         10.7
01005      12.5         14.4
02003       0.0          5.5
02003       7.2         10.2


In the above result, the first line has 10.7 as the End, and the second line has 12.5 as the Begin -- meaning that there is a gap, so both records should be shown. Same with the third and fourth lines. This is done for each RoadID, so for example, even though there is a gap between these two records (16.9 <> 0.0), they should not be shown in the result because their RoadID values are different (01005 and 01002):

01005      14.4         16.9
01002       0.0         13.2


I have tried to use some inner join tricks but could not get a thing. I could do this through a program, but I am curious to know if a single SQL query could achieve it. Any help on this is appreciated. Thanks!
QuestionRe: SQL question Pin
Jörgen Andersson31-Mar-11 8:45
professionalJörgen Andersson31-Mar-11 8:45 
GeneralRe: SQL question Pin
loyal ginger31-Mar-11 9:06
loyal ginger31-Mar-11 9:06 
GeneralRe: SQL question [modified] Pin
Jörgen Andersson31-Mar-11 9:38
professionalJörgen Andersson31-Mar-11 9:38 
GeneralRe: SQL question Pin
loyal ginger31-Mar-11 10:16
loyal ginger31-Mar-11 10:16 
AnswerRe: SQL question Pin
Jörgen Andersson31-Mar-11 10:28
professionalJörgen Andersson31-Mar-11 10:28 
GeneralRe: SQL question Pin
loyal ginger1-Apr-11 3:23
loyal ginger1-Apr-11 3:23 
AnswerRe: SQL question Pin
Wendelius31-Mar-11 9:14
mentorWendelius31-Mar-11 9:14 
GeneralRe: SQL question Pin
loyal ginger31-Mar-11 10:17
loyal ginger31-Mar-11 10:17 
QuestionThis one has me stumped Pin
Andy Brummer31-Mar-11 6:01
sitebuilderAndy Brummer31-Mar-11 6:01 
AnswerRe: This one has me stumped Pin
Wendelius31-Mar-11 6:45
mentorWendelius31-Mar-11 6:45 
Generalvirtual keyboard Pin
shelbypowell31-Mar-11 4:02
shelbypowell31-Mar-11 4:02 
GeneralRe: virtual keyboard Pin
Mycroft Holmes31-Mar-11 13:09
professionalMycroft Holmes31-Mar-11 13:09 
GeneralRe: virtual keyboard Pin
shelbypowell31-Mar-11 13:58
shelbypowell31-Mar-11 13:58 
GeneralRe: virtual keyboard Pin
Mycroft Holmes31-Mar-11 14:17
professionalMycroft Holmes31-Mar-11 14:17 
GeneralRe: virtual keyboard Pin
Pete O'Hanlon31-Mar-11 23:35
mvePete O'Hanlon31-Mar-11 23:35 
GeneralRe: virtual keyboard Pin
Andy_L_J31-Mar-11 23:56
Andy_L_J31-Mar-11 23:56 
GeneralRe: virtual keyboard Pin
shelbypowell1-Apr-11 1:05
shelbypowell1-Apr-11 1:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.