Skip to content
Advertisement

I would like to order in SQL server where the first line is the same, but later it’s different

The point in this case is that the starting point is the same for a line, let’s say a train line. The line starts on the same point, but ends on different end points. The services depends on the line where they are riding.

I’ve added the extra requested information, this could be extended with more lines.

Example table:

Initial situation:

Expected result:

If one extra row is added to the example input, the output would change as follows…

Example table:

Initial situation:

Expected result:

Advertisement

Answer

You appear to be describing a tree structure…

The results would then be both (all) paths from the root node.


EDIT:

Minor corrections made, and this link to a working demo…

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement