我在有向图中有一张保持边的表格:
CREATE TABLE edges (
from_here int not null,
to_there int not null
)如何在此表上进行选择而不考虑所有反向链接?例如,从本表中:
+------------+----------+--+
| from_there | to_there | |
+------------+----------+--+
| 1 | 2 | |
| 2 | 1 | |
| 3 | 4 | |
+------------+----------+--+我想得到这个结果:
+------------+----------+--+
| from_there | to_there | |
+------------+----------+--+
| 1 | 2 | |
| 3 | 4 | |
+------------+----------+--+换句话说,如何才能得到每个双向链路--仅仅是前向链路?我们不能假定互惠边总是存在的。
编辑目标是每个双向链接获得一行,不管是前向还是后向链路。
发布于 2014-08-22 13:31:36
如果我做对了
select from_there, to_there
from edges x
where not exists (
select 1 from edges y
where x.from_there = y.to_there
and x.to_there = y.from_there
and x.to_there < y.to_there
);https://stackoverflow.com/questions/25448033
复制相似问题