内侧连接两次返回任何结果
我命名节点的两个表格和链接,就像这样:内侧连接两次返回任何结果
--Links: -----------------------------------
id fromx fromy tox toy
-----------------------------------
a1 x1 y1 x2 y2
a2 x2 y2 x3 y3
a3 x2 y2 x4 y4
a4 x1 y1 x4 y4
a5 x1 y1 x5 y5
--Nodes:
id x y
--------------
1 x1 y1
2 x2 y2
3 x3 y3
4 x4 y4
5 x5 y5
我想通过匹配fromx,弗罗米和TOX,玩具生产第三个表在打击的节点表中的X和Y链接表产生一个表像这样:
linkid fromid toid --------------------
a1 1 2
a2 2 3
a3 2 4
a4 1 4
a5 1 5
在努力达到那个结果,我用这个查询使用上的节点表连接两次以下查询,但我没有得到任何结果。
select links.id as linkid, n1.id as nodeid, fromx, fromy, tox from links
inner join nodes n1
inner join nodes n2
on
links.fromx = n1.x
and links.fromy = n1.y
and links.tox = n2.x
and links.toy = n2.y
我“很高兴来创建临时表或者这样,如果这将有助于。
回答:
select l.id as link_id,
frm.id as from_id,
t.id as to_id
from
links l
inner join
nodes frm
on frm.x = l.fromx
and frm.y = l.fromy
inner join
nodes t
on t.x = l.tox
and t.y = l.toy
SQL Fiddle
以上是 内侧连接两次返回任何结果 的全部内容, 来源链接: utcz.com/qa/260916.html