SQL Association Table query Results and insert

Source: Internet
Author: User

Here are three tables, AA,BB,CC, the AA data is updated to the CC table, the AA label_id respectively intercept the field and the BB table label_id corresponding query to Label_name as a field of the CC table Insert, here divided into four sections of the query

INSERT INTO CC

Select T.apmac,t1. Label_name,t2. Label_name,t3. Label_name,t4. label_name,t.label_id, ' Hangzhou '

From (select A.ap_mac as apmac,a.label_id, substr (a.label_id,3,2) as Level1,substr (a.label_id,5,2) as Level2,

SUBSTR (a.label_id,7,3) as Level3,substr (a.label_id,10,3) as Level4 from AA a) T,

(SELECT * from BB where label_level= ' level ') T1,

(SELECT * from BB where label_level= ' two level ') T2,

(SELECT * from BB where label_level= ' three level ') T3,

(SELECT * from BB where label_level= ' four level ') T4

WHERE T1. Label_id=t.level1 and T2. Label_id=t.level2 and T3. Label_id=t.level3 and T4. Label_id=t.level4

SQL Association Table query Results and insert

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.