3

I have a table with routes like this:

Source - Destination
Bogota - Monteria
Monteria - Bogota
Cali - Bogota
Bogota - Medellin

I want to only select one way of the route to display it on a map. So as a result i want only

Bogota - Monteria
Cali - Bogota
Bogota - Medellin

Can any one point me in the right direction?

4

1 回答 1

3

您可以使用一条CASE语句,以便按照字母顺序为路线末端分配一致的列。

SELECT DISTINCT CASE
                  WHEN Source > Destination THEN Destination
                  ELSE Source
                END,
                CASE
                  WHEN Source > Destination THEN Source
                  ELSE Destination
                END
FROM   Routes 
于 2013-06-30T11:28:49.833 回答