Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 mySQL 表上有一个 Graph 表示为:
uidFrom, uidTo 1 4 4 1 1 5 5 1 6 1 <- only incoming edge
如何只获得“6, 1”对,只有“1”作为输入?我的意思是,如何查询节点“1”的唯一传入边(而不是像 4 或 5 这样的传入和传出)?
提前致谢;
你可以这样做:
SELECT uidFrom, uidTo FROM Graph g WHERE NOT EXISTS ( SELECT * FROM Graph rev WHERE rev.uidFrom=g.uidTo AND rev.uidTo=g.uidFrom )
这是关于 sqlfiddle 的演示。