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


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


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

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 江安县| 河东区| 宜阳县| 雷州市| 密云县| 松桃| 鱼台县| 彭州市| 齐齐哈尔市| 姜堰市| 年辖:市辖区| 通榆县| 临高县| 广昌县| 宝鸡市| 岫岩| 海伦市| 普宁市| 板桥市| 望奎县| 怀化市| 博湖县| 宁河县| 连南| 麟游县| 铜梁县| 吴川市| 崇礼县| 象山县| 新闻| 三台县| 佛山市| 宜黄县| 剑阁县| 皮山县| 宁都县| 留坝县| 磐石市| 新乐市| 阳曲县| 铜山县|