本文介绍了如何匹配对角线上两列(同一张表)的值,不匹配时显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 city
表,它有两列
I have a city
table that has two columns
from_city
to_city
现在假设一行具有以下值
now lets assume that one row has the following values
'lahore'
'peshawar'
而下一行有
'peshawar'
'lahore'
请注意,这些值是对角匹配的.我想以这种方式显示所有不匹配的行.
Notice that the values match diagonally. I want to display all the rows that don't match in such a manner.
任何帮助将不胜感激.
推荐答案
可能是这样的:
SELECT *
FROM bus_route b1
LEFT JOIN bus_route b2 ON b1.from_city=b2.to_city AND b1.to_city=b2.from_city
WHERE b2.from_city IS NULL
这篇关于如何匹配对角线上两列(同一张表)的值,不匹配时显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!