我有像這樣的表:MYSQL - WHERE在兩列中的值
id | node_source | node_destination | path
1 | 1 | 0 | {"coordinates": [[-6.27400693507...
2 | 0 | 1 | {"coordinates": [[-6.24568104953...
3 | 1 | 2 | {"coordinates": [[-6.24568104953...
4 | 2 | 1 | {"coordinates": [[-6.27230059993...
我想行1和行2,行3和行4
之間比較node_source和node_destionation的值如果node_source在第1行== node_destination在第2行AND node_destination在第1行== node_source在第2行THEN只顯示第一行(id = 1)
if row_strings == node_destination in row 4 AND node_destination in第3行==第4行中的node_source THEN僅顯示第三行(id = 3)
最終的輸出是這樣的:
id | node_source | node_destination | path
1 | 1 | 0 | {"coordinates": [[-6.27400693507...
3 | 1 | 2 | {"coordinates": [[-6.24568104953...
這裏我的代碼(但不工作):
SELECT * FROM graph t1
WHERE NOT EXISTS(SELECT * FROM graph t2
WHERE t2.node_source = t1.node_destination AND t2.node_destination = t1.node_source
)
幫助。 謝謝。
也比較但是,如果我改變第二行與: 'id | node_source | node_destination | 2 | 4 | 1 \t \t |' 輸出將會不同: 'id | node_source | node_destination |路徑 2 | 4 | 1 | {「coordinates」:[[-6.24568104953 ... 3 | 1 | 2 | {「coordinates」:[[-6.24568104953 ...' – ahm
據我瞭解,在這種情況下,你應該得到行1,2和3,這就是查詢將帶來什麼 – user3600910