SQL Query CET use comprehension

Source: Internet
Author: User

Using the SQL Traversal loop query, if you do not consider using CET, the estimated time to build their own wheels, now think that the SQL CET is really a good thing, for SQL recursive query, is a good way;

 withEtcRecommandINfo2 (C_precommendno,c_recommendname,c_recommendno,i_rtype,c_serverdir,c_pic_recommend,tlevel)  as(    SelectC_precommendno,c_recommendname,c_recommendno,i_rtype,c_serverdir,c_pic_recommend,0  asTlevel fromRecommendwhereC_recommendno='RC20150514142804'    Union  All    SelectRd.c_precommendno,rd.c_recommendname,rd.c_recommendno,rd.i_rtype,rd.c_serverdir,rd.c_pic_recommend,et.tlevel+1  fromRecommend RdInner JoinEtcRecommandINfo2 ET onEt.c_precommendno=Rd.c_recommendno)SelectC_precommendno,c_recommendname,c_recommendno,i_rtype,c_serverdir,c_pic_recommend,tlevel fromEtcRecommandINfo2;

After reading this code, you may be drunk, in fact, this code, mainly used in CET, first of all, this use to query this table:

C_recommendno
Identifies a unique in the table
C_precommendno
Identifies the previous piece of data for this piece of data

This is the main 2 fields, and these two fields are the root of the recursion.

This statement can be understood in 3 steps, such as:

1, query the basic data;

2, the basic data related conditions, query all data;

3, the query data, through with the classification display processing;

*************************************************************

**************************************************************

NOTE: Statement 2 in the following statement is also very important, = the order of the left and right is not interchangeable, after the interchange, the results of the query is not the same; remember the order of understanding is key, understand the order, you can query the results you want;

For more information on CET, refer to the link:

Http://www.cnblogs.com/kissdodog/archive/2013/06/24/3153012.html

SQL Query CET use comprehension

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.