如何将复杂的SQL查询转换为Zend_Db_Select语句?
技术问答
287 人阅读
|
0 人回复
|
2023-09-12
|
MySQL该网站提供了一个关于在数据库中存储层次结构数据的优秀教程。我正试图编写直接子级查询返回节点。我不想仅仅从MySQL网站复制/粘贴查询,因为我试图以与数据库无关的方式处理这个问题。
- @& [4 F" G; U我正在尝试Zend_Db_Select-ify的查询+ J# y8 b/ W, ?( r* V
SELECT node.name,(COUNT(parent.name) - (sub_tree.depth 1) AS depthFROM 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_treeWHERE 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.nameGROUP BY node.nameORDER BY node.lft; 8 f0 T1 s6 D% H& [3 F/ j
解决方案: |
|
|
|
|
|