MySQL網站在將分層數據存儲在數據庫中時有一個excellent tutorial。我試圖編寫返回節點的直接子節點的查詢。我不想從MySQL網站複製/粘貼查詢,因爲我試圖以數據庫不可知的方式處理這個問題。如何將複雜的SQL查詢轉換爲Zend_Db_Select語句?
這是我想查詢Zend_Db_Select對象,IFY
SELECT node.name, (COUNT(parent.name) - (sub_tree.depth + 1)) AS depth
FROM nested_category AS node,
nested_category AS parent,
nested_category AS sub_parent,
(
SELECT node.name, (COUNT(parent.name) - 1) AS depth
FROM nested_category AS node,
nested_category AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.name = 'PORTABLE ELECTRONICS'
GROUP BY node.name
ORDER BY node.lft
)AS sub_tree
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt
AND sub_parent.name = sub_tree.name
GROUP BY node.name
ORDER BY node.lft;
+1僅用於鏈接到教程! – Marcin 2011-02-03 08:37:55