ORACLE
select id,name,parentid,level from (
SELECT id,name,parentid,level
FROM treeTable
START WITH id = '某某条件'-- 开始检索的条件
CONNECT BY PRIOR parentid= id)
where level=1 -- 取最上级
SQL Server
WITH TREE AS(
SELECT id,name,parentid,level
FROM treeTable
WHERE id ='条件'
UNION ALL
SELECT a.id,a.name,a.parentid,a.level
FROM treeTable a, TREE
WHERE a.ID = TREE.parentid)
SELECT id,name,parentid,level FROM TREE
where tree.level=1