当前位置:数据库 > Oracle >>

oracle树形结构相关查询


oracle树形结构相关查询
 
查询最顶层元素
   www.zzzyk.com  
select * from basic_type t WHERE NOT exists(select 'x' from basic_type t1,
basic_type t2 where t1.id=t2.parentid and t1.id= t.parentid)
 
查询id为'asdfas'的属于顶层ID为4的第几级
 
 select * from (select LEVEL,id,parentid,name from basic_type START WITH id='4'  
   CONNECT BY PRIOR id=parentid) where id= 'asdfas'
Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,