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