mysql - 在 MySQL 中获取所有具有路径的父母
问题描述
我有一张像这样的桌子;
id | rank | path
---+------+-------
1 | NULL | NULL
2 | 1 | /1/2/
3 | 2 | /1/2/3/
4 | 2 | /1/2/3/
5 | 3 | /1/2/3/5/
6 | 1 | /1/6/
给定从 id 5 或 id 5 开始的路径,希望所有父母都喜欢;
1 | NULL | NULL
2 | 1 | /1/2/
3 | 2 | /1/2/3/
4 | 2 | /1/2/3/
5 | 3 | /1/2/3/5/
或者
1 | NULL | NULL
2 | 1 | /1/2/
3 | 2 | /1/2/3/
4 | 2 | /1/2/3/
试过这里的建议SQL: How to select all parent nodes in Materialized path? 但没有成功。
我尝试的查询是:
SELECT * FROM table
WHERE '/1/2/3/5/' LIKE id||%
ORDER BY path
此外,我查看了来自 - https://communities.bmc.com/docs/DOC-9902 - https://www.sqlteam.com/articles/more-trees-hierarchies-in-sql的查询
其中。找不到适合这个的东西。
请协助。
解决方案
推荐阅读
- javascript - 事件处理程序未在组件呈现之前设置状态
- javascript - 如果单元格更改为空白,Google Script Javascript 阻止日期输入
- javafx - JavaFx:关于节点和场景
- bash - bash 完成的编号选项
- javascript - react-testing-library 渲染功能有什么问题?它在某些对象上返回错误
- python - 带参数查询的元数据库 API 请求限制为 2000 行
- sql - initcap 仅适用于超过三个字符的单词
- react-native - 如何从导入的子组件(导航组件)在应用程序中使用导航?
- node.js - 将应用程序联机时出现提取问题(Node.js -> Heroku)
- react-native - 安装 fs-extra 时失败 - react-native