Challenge: SQL check next record against previous -


I have some data that needs to be confirmed, and when I get a quick formula working in Excel then I Some of the SQL can be found that can do the same, so I can use it as a check in my database.

The data is only:

  ACACIA ST (KLN) | 1073 | 1149 | Failed! | 76 ACASIA ST (KLN) | 1073 | 1151 | Failed! | 78 ACACIA ST (KLN) | 1150 | 1332 | Failed! | 182 ACASIA ST (KLN) | 1151 | 1332 | Failed! | 181 ACASIA ST (KLN) | 1606 | 2079 | | 473 Activity ST (WRK) | 6 | 215 | win! | 20 9 Activity ST (WRK) | 215 | 227 | win! | 12 Activity ST (WRK) | 227 | 423 | win! | 196 Activity ST (WRK). 423 | 54 9 win! | 126 Activity ST (WRK). 54 9 600 | | 51 Adrian CT (WMN) | 5 | 107 | win! | 102 Adrian CT (WMN). 107 | 122 | | 15 Aerodrome RD (LYB). 0 | 140 | win! | 140 Aerodrome RD (LYB) | 140 | 428 | win! | 288 Eroderome RD (LYB) | 428 | 716 | win! | 288 Eroderome RD (LYB) | 716 | 998 | win! | 282 Eroderome RD (LYB) | 998 | 1280 | win! | 282 Eroderome RD (LYB) | 1280 | 1566 | win! | 286 Aerodrome RD (LYB) | 1566 | 1851 | win! | 285 Aerodrome RD (LYB). 1851 | 2136 | win! | 285 Aerodrome RD (LYB). 2136 | 2421 | | 285  

Well there is a lot of data, that is, ~ 11000 + rows.

Now the idea is that each road segment (first column) should be a starting and end series (second and third column) and a length (the last column), the intermediate series should be the starting chain of the next section, provided The name of the road segment is the same (definitely according to the earlier series). You can see that the chains at the end of the first lines are not equal to the beginning of the next, it fails.

My bad attempt on pseudocode:

  If the endeck! = NextStartChainge where Road Segment = NextRoadSegment error  

I need to be able to select all the road segments that do not follow the rule of the end series = Chainz chain next to the next.

Then the above table will be out:

  ACACIA ST (KLN) | 1073 | 1149 | Failed! | 76 ACASIA ST (KLN) | 1073 | 1151 | Failed! | 78 ACACIA ST (KLN) | 1150 | 1332 | Failed! | 182 ACASIA ST (KLN) | 1151 | 1332 | Failed! | 181  

Hope that makes sense I tried to do it, but it may still seem to work, and there is a lack of my SQL skills.

Edit: I can use both SQL Server and PostgreSQL.

Assume that there will be no duplicate lines, the following DB-agnostic solution should be: Choose Street, Starto, Endo, Case (Selection Collage (Minimum (s2.startno), - 1) Stackcllase S2 where s1.street = s2.street and s1.startno & lt ; = S2.startno and s1.endno & lt; s2.endno) when '1' then 'end' then 'win!' Other 'Fail!' As the valid end, the stackchallenge s1 sequence lengths 1,2,3


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -