SQL递归查询

oracle:
select id ,name from base_city start with base_city.id=10002 CONNECT by PRIOR base_city.id=base_city.parentid;

postgreSql:

WITH RECURSIVE r AS (select id ,name,parentid from base_city  WHERE id=10002
union ALL
 SELECT base_city.id ,base_city.name,base_city.parentid FROM base_city, r WHERE base_city.parentid = r.id
 )

SELECT * FROM r ;


with RECURSIVE r as(select * from ry_travel_area where id = 1
    union all select ry_travel_area.* from r, ry_travel_area where r.id = ry_travel_area.p_id)
 delete from ry_travel_area where exists (select id from r where r.id = ry_travel_area.id)

posted on 2013-03-12 13:27 Mr.lu 阅读(380) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年3月>
242526272812
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(2)

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜