SQL Dameng database parent-child table (tree table) query all subsets, parent

SQL Dameng database parent-child table (tree table) query all subsets, parent

Look at the table first.
insert image description here
In the figure, dic_id is the child key parent_dic_id is the parent key, that is, dic_ic = parent_dic_id

Now to find out all the subsets whose parent id is 1

The sql corresponds to:
some are shown below 内联代码片.

select * from T_SYS_DIC 
start with dic_id = '1000076' CONNECT BY PRIOR dic_id =  parent_dic_id

Corresponding results: It can be seen that all the data are subsets whose parent id is 1000076.
insert image description here
Note: PRIOR usage , put before the child id to find the data, all the subsets under the child id
insert image description here
are placed before the parent id to find the data for the parent id See the effect on all parents
insert image description here
results:
insert image description here

This data is learning and testing data. If necessary, please change it to your own corresponding business data. Welcome to advise!

Guess you like

Origin blog.csdn.net/weixin_51114236/article/details/125022240