我需要比較同一列中的行,所以我有以下mysql查詢哪些運作良好給予預期的結果。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,無法在此查詢上創建視圖。任何人都可以提出一個更好的方法來做出這樣的查詢,特別關注速度,實際上這個查詢是非常緩慢的。謝謝。
請爲此聲明發布'EXPLAIN'。 (發佈=更新您的問題) – Kermit 2013-04-09 02:53:09