Home > database >  What is SQL recursive principle
What is SQL recursive principle

Time:12-02

See BBS will be a lot of time using recursive CTE problem solving, to simulate the case, don't see how system is implemented
 -- doubt 
- I want to check under the city, fujian province, for example, imitating the writing on the net can implement effect, just don't understand the principle of recursive, could help explain, the following case is system works
- the fifth line INNER JOIN A ON A.C ode=T.p arentCode don't understand, help detailed description points as far as possible, thank you!
Select * into # t the from (
Select '01' as Code, ' 'in fujian province Name,' 0 'parentCode, 1 level union all
Select the '02' as Code, 'Shanghai' Name, '0' parentCode, 1 level union all
Select '0101', 'xiamen', '01, 2 union all
Sanming city, select '0102', ' 'and' 01, 2 union all
Select '010101', 'the Amoy area', '0101', three union all
Select '010102', 'in the lake area', '0101', three union all
Select '0103', 'fuzhou', '01, 2 union all
Quanzhou city select '0104', ' ', '01, 2 union all
Jiading district, select '0201', ' ', '02', 2 union all
Select '020101', 'yellow cross the town', '0201', three union all
Select '020102', 'league west village', '0201', three union all
Songjiang select '0202', ' ', '02', 2) A


With A as (
SELECT Code, Name, parentCode, level FROM WHERE Code # t=01
Union all
The SELECT tc ode, T.N ame, T.p arentCode, T.l evel FROM # t t
INNER JOIN A ON A.C ode=T.p arentCode - this sentence don't understand, associated within A table, A not in outer how can link, also we normally associated are associative table, or (select * FORM table) as A this kind of table
)

SELECT * FROM A
  • Related