树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
相关问答:
我EXCEL中一个单元格的数据如 "2009-01","8949-232"
将这个数据粘贴到PL/SQL中的一个表中后,数据确是成为了 2009-01,8949-232 ,把所有的""都没了,
如何弄呢?请大家试 ......
PB中开发的。
DateTime startTime=DateTime(em_1.Text)
DateTime endTime=DateTime(em_2.Text)
string sql
sql = dw_1.GetSQLSelect()+"Where (StartTime> '"+startTime+&q ......
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
查询语句如下:
str="15,17,50,4,7,6,25"
sql = "select * from table where ID in(" & str & ")"
response.write rs("id") & " <br>&quo ......
table有大致如下的记录,这些记录已经是按照规定要求排序好的了
field1 field2
A B
B F
C D
E F
F A
...
我要实现的效果
field
A
B
F
C
D
E
... ......