像这样的东西:
WITH RECURSIVE hierarchy (folderid, ParentFolderId, FolderName) as ( SELECt folderid, ParentFolderId, FolderName FROM folders WHERe ParentFolderID = -1 UNIOn ALL SELECt folderid, ParentFolderId, FolderName FROM folders f JOIN hierarchy p ON p.folderID = f.parentFolderID)SELECt *FROM hierarchy
编辑 :以下查询将使层次结构“向上”,找到给定文件夹的所有父级。
WITH RECURSIVE hierarchy (folderid, ParentFolderId, FolderName) as ( SELECt folderid, ParentFolderId, FolderName FROM folders WHERe folderid = 42 UNIOn ALL SELECt folderid, ParentFolderId, FolderName FROM folders f JOIN hierarchy p ON p.parentFolderID = f.folderID)SELECt *FROM hierarchy
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)