Implement recursive query using SQL

Source: Internet
Author: User


Use SQL to recursively query whether the primary key parent node is named to describe the leaf www.2cto.com node RES_CAT_ID IS_LEAFNODE 1 127f 1 0 Agricultural Science 0 06-12 months-12 03.52.09.074000 PM 3 127f 1 0 plant protection 0 06-12 months-12 03.52.34.545000 Pm 4 * F 1 0 crop Crop 0 06-12 months-12 03.52.50.804000 PM 5 1 1 1 1 Basic Agricultural Discipline 0 06-12 months-12 03.53.24.490000 PM 6 1 1 1 plant protection 0 06-12 months-12 03.53.43.328000 PM 7 2 1 1 Soil Science 0 07-12 months-12 10.34.10.163000 am 8 127f 1 1 animal husbandry 0 07-12 months-12 10.38.43.331000 AM 2. F 1 0 basic agricultural science 0 06-12 months-12 03.52.23.398000 afternoon RES_CAT_PAR_ID first column: RES_CAT_ID second column: RES_CAT_PAR_ID third column: IS_LEAFNODE query data of all leaf nodes of a node select t. res_cat_id, t. res_cat_name, t. res_cat_par_id from irc_res_cat t where t. res_cat_id <> '2' start with t. res_cat_id = '2' connect by prior t. res_cat_id = t. res_cat_par_id and t. is_del = '0' and t. is_leafnode = '1'
Query all the leaf node data in the root directory select t. res_cat_id, t. res_cat_name, t. res_cat_par_id from irc_res_cat t where t. res_cat_par_id = '1 _ F' and t. is_leafnode = '1'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.