我需要比较同一列中的行,所以我有以下 mysql 查询,它可以很好地给出预期的结果。
SELECT x.aord,
x.anode AS parent,
x.bnode AS child
FROM (SELECT a.ordinal AS aord,
a.id_dt_graph_node_edge AS aid,
a.id_dt_graph_node AS anode,
b.ordinal AS bord,
b.id_dt_graph_node_edge AS bid,
b.id_dt_graph_node AS bnode
FROM dt_graph_node_edge a
JOIN dt_graph_node_edge b
ON a.ordinal < b.ordinal) x
LEFT JOIN (SELECT a.ordinal AS aord,
a.id_dt_graph_node_edge AS aid,
a.id_dt_graph_node AS anode,
b.ordinal AS bord,
b.id_dt_graph_node_edge AS bid,
b.id_dt_graph_node AS bnode
FROM dt_graph_node_edge a
JOIN dt_graph_node_edge b
ON a.ordinal < b.ordinal) y
ON x.aord = y.aord
AND x.bord > y.bord
WHERE y.bord IS NULL
ORDER BY x.aord,
x.bord
我发现由于错误 #1349,无法在此查询上创建视图。任何人都可以提出一种更好的方法来进行这样的查询,特别关注速度,实际上这个查询非常慢。谢谢。