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 閱讀(383) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          <2013年3月>
          242526272812
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 望城县| 壶关县| 新田县| 响水县| 津南区| 江北区| 鲁甸县| 乐亭县| 新竹县| 富锦市| 磐石市| 朝阳市| 鹰潭市| 奈曼旗| 临洮县| 合山市| 丹东市| 施秉县| 常山县| 道真| 揭东县| 阿克陶县| 屯昌县| 庆安县| 镇原县| 乌拉特后旗| 西贡区| 绥化市| 怀集县| 福海县| 宁安市| 平和县| 濮阳市| 吉水县| 阳春市| 南阳市| 睢宁县| 翁牛特旗| 花垣县| 万年县| 柳河县|