相関サブクエリを使用してからしばらく経ちましたが、これが正しいかどうかはわかりません。サブクエリの最後の 2 行目でnode.id
、外部テーブルから取得しようとしています。クエリを実行しようとすると、
エラー コード: 1054 'where 句' の列 'node.id' が不明です)
select node.id, node.title, depthLookup.depth
from posts node, (
select count(parent.title) as depth
from posts parent, posts children
where children.lft > parent.lft
and children.rgt < parent.rgt
and children.id = node.id
order by parent.lft
) as depthLookup;