"DB2" GB industry classified storage, through SQL query out hierarchical relationship

Source: Internet
Author: User
Tags db2

New Table

DROP TABLE Industry; CREATE TABLE Industry (industrycode varchar (+), industryname varchar, parentid varchar (40))


Click to download INSERT statement


Data:

Now that the data is this way, we need to find the corresponding hierarchical relationship, for example:

Implement SQL as follows:

SELECTA. IndustryCode as Class01,a.industryname Class_01nm,b.industrycode as Class02,b.industryname CLASS_02NM,C.IndustryCode As Class03,c.industryname Class_03nm,c.industrycode as Class04,c.industryname Class_04nm,dense_rank () over (ORDER by A. IndustryCode) seqfrom industry a,industry b,industry c,industry dwhere A.industrycode=b.parentid and B.INDUSTRYCODE=C. ParentID and C.industrycode=d.parentid

"DB2" GB industry classified storage, through SQL query out hierarchical relationship

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.