当前位置:网站首页>Implementation of SQL Server recursive query in highgo dB (APP)

Implementation of SQL Server recursive query in highgo dB (APP)

2021-01-18 14:19:47 Hangao PG Laboratory

Catalog
Environmental Science
Document purpose
Details
 
Environmental Science
system platform : Microsoft Windows (64-bit) 10
edition : 5.6.4
 
Document purpose

stay Highgo DB And SQL Server Recursive query with the same effect

 
Details

1、SQL Server Table creation and test data addition

 

Create table GroupInfo([Id] int,[GroupName] nvarchar(50),[ParentGroupId] int)

 

 

Insert GroupInfo

select 0,' XXX university ',null union all

select 1,' Foreign language college ',0 union all

select 2,' English major ',1 union all

select 3,' Japanese professional ',1 union all

select 4,' English major class 1 ',2 union all

select 5,' English major class 2 ',2 union all

select 6,' Japanese major 1 ',3 union all

select 7,' Class 2, Japanese major ',3 union all

select 8, ' Law school, ',0 union all

select 9, ' Major of criminal law ',8 union all

select 10,' Economic law ',8 union all

select 11,' Class 1, criminal law ',9 union all

select 12,' Class 2, criminal law major ',9 union all

select 13,' Class 1, economic law ',10 union all

select 14,' Class 2, economic law major ',10

 

2、SQL Server Recursive query statement

 

-- Construct a recursive path

with

CTE

as

(

    select Id,GroupName,ParentGroupId,GroupPath=CAST( GroupName as nvarchar(max)) from GroupInfo where Id=0

    union all

    select G.*,CAST(CTE.GroupPath+'//'+G.GroupName as nvarchar(max)) as GroupPath from CTE

    inner join GroupInfo as G on CTE.Id=G.ParentGroupId

)

select * from CTE order by ParentGroupId

For more details, please visit 【 Hangao technology support platform 】 see https://support.highgo.com/#/index/docContentHighgo/414ab22e059c9985 

版权声明
本文为[Hangao PG Laboratory]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/01/20210118141821057G.html

随机推荐