我有一张巴士详情表。 它有bus_name,bus_source和bus_destination。 我需要知道哪些公交车可以回程。 例如
bus_name | bus_source | bus_destination
a | Chennai | Bangalore
b | Bangalore | Chennai
c | Mumbai | Chennai
我希望如此:
bus_name | bus_source | bus_destination
a | Chennai | Bangalore
b | Bangalore | Chennai
答案 0 :(得分:2)
使用EXISTS()
:
SELECT * FROM YourTable t
WHERE EXISTS(SELECT 1 FROM YourTable s
WHERE t.bus_source = s.bus_destination
AND t.bus_destination = s.bus_source);