lzth.net
相关文档
当前位置:首页 >> mysql递归 >>

mysql递归

with a as (select * from table1 where parentid=0 union all select b.* from a,table1 b where a.id=b.parentid) select * from a 用with as 来实现递归

概念说不一定理解,给你一个例子你自己参悟。 SELECT TEACHER FROM C AS X WHERE UNIQUE(SELECT TEACHER FROM C AS Y WHERE Y.TEACHER=X.TEACHER);

表结构,表数据发出来看看

--创建表DROP TABLE IF EXISTS `t_areainfo`;CREATE TABLE `t_areainfo` ( `id` int(11) NOT '0' AUTO_INCREMENT, `level` int(11) DEFAULT '0', `name` varchar(255) DEFAULT '0', `parentId` int(11) DEFAULT '0', `status` int(11) DEFAULT '...

给你个网上写的比较好的例子: 方法一:利用函数来得到所有子节点号。 创建一个function getChildLst, 得到一个由所有子节点号组成的字符串. mysql> delimiter // mysql> mysql> CREATE FUNCTION `getChildLst`(rootId INT) -> RETURNS varchar(...

mysql> create table treeNodes -> ( -> id int primary key, -> nodename varchar(20), -> pid int -> ); Query OK, 0 rows affected (0.09 sec) mysql> select * from treenodes; +----+----------+------+ | id | nodename | pid | +----+---...

with a as (select * from table1 where parentid=0 union all select b.* from a,table1 b where a.id=b.parentid) select * from a 用with as 来实现递归

function sumShuzi(&$tree, &$updateData = array()) { $sum = 0; // foreach($tree as $key => $item) { //这句话有毒 foreach($tree as $key => &$item) { if(isset($item['children'])) { $oldPshuzi = $tree[$key]['Pshuzi']; $tree[$key]['...

mysql中没有递归删除语句。需要用存储过程。 http://blog.csdn.net/ACMAIN_CHM/article/details/4142971

主要看设计思路问题,执行效率,可读性,可维护性,兼容性等反面的考虑,没事绝对的最好与最差之说

网站首页 | 网站地图
All rights reserved Powered by www.lzth.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com