树sql,不知道如何写
一个树sql,不知道如何写(正在考虑用存储过程)
a表 2个字段(id, parentid)
id, parentid
1 0
2 1
3 2
4 1
5 2
先在我需要得到以下的结果
1 0
2 1
3 2
5 2
4 1
.。。。。
请问如何做(左子树遍历完 再继续左子树 右子树遍历)
1 CREATE TABLE `tree` (
`id` int(10) NOT NULL,
`fid` int(10) NOT NULL );
create table if not exists tmp_table(id bigint(20),fid bigint(20),lvl int)//
2 CREATE PROCEDURE useCursor(iid bigint(20),lvl int)
BEGIN
declare tid bigint(20) default -1 ;
declare tfid bigint(20) default -1 ;
declare cur1 CURSOR FOR select id,fid from tree where fid=iid ;
declare CONTINUE HANDLER FOR SQLSTATE '02000' SET tid = null,tfid=null;
SET @@max_sp_recursion_depth = 10;
OPEN cur1;
FETCH cur1 INTO tid,tfid;
WHILE ( tid is not null )
DO
insert into tmp_table values(tid,tfid,lvl);
call useCursor(tid,lvl+1);
FETCH cur1 INTO tid,tfid ;
END WHILE;
END;
DELIMITER ;
3test:
delete from tmp_table ;
call useCursor(0,0);
select * from tmp_table ;
mysql 树形结构查询(存储过程)
减小字体 增大字体
就用数据数据库表地址数据(中国地区) 来说吧(用Window
相关问答:
本人c#新手 可是要求要用c# ,sql2000开发c/s的工作流,一头雾水,请大家帮忙帮忙,给点思路,说的约具体越好,我也好往那个方面去学习
http://www.hxzi.com/view/61402.html
B/S版的,基本思想应该差不多的。。 ......
....接到一个小程序..工作原来大概是这样的...前台是WEB服务器.架构就是ASP+SQL..前台由ASP向SQL添加服务类别(表单).然后又后台程序读取表单..要实时读取..然后显示在服务器上面..从理论上面能行通不?如果可以..后台 ......
两种错误:
1.如果我这样申明:ResultSet rs;错误提示如下:
An error occurred at line: 51 in the jsp file: /index.jsp
The local variable rs may not have been initialized
48: ......
我EXCEL中一个单元格的数据如 "2009-01","8949-232"
将这个数据粘贴到PL/SQL中的一个表中后,数据确是成为了 2009-01,8949-232 ,把所有的""都没了,
如何弄呢?请大家试 ......
表A
Sup_code st_sup_code buy_code buy_code1
1001 400 &nbs ......