一条SQL语句查询无限递归树所有数据

权限树:SELECT PERMISSIONID, PARENTID, T.ITEMNAME,T.DESCRIPTION FROM T_PERMISSION T START WITH PARENTID = (SELECT PARENTID FROM T_PERMISSION WHERE PERMISSIONID = 0) CONNECT BY PRIOR PERMISSIONID = PARENTID ORDER BY PARENTID


机构树:

SELECT AGENCYID, PARENTID, T.AGENCYNAME FROM T_AGENCY T START WITH PARENTID = (SELECT AGENCYID FROM T_AGENCY WHERE AGENCYID = 0) CONNECT BY PRIOR AGENCYID = PARENTID ORDER BY PARENTID


以上是两个样例,而不是需要两个语句,只用一条语句即可。

定义数据库的时候需要定义一个ID和一个父ID,这样就可以形成无限递归树了。

你可能感兴趣的:(一条SQL语句查询无限递归树所有数据)