我有以下的列如何让所有的孩子记录在MYSQL分层数据
id | parent_customer_id
-----------------------------
1 | 0
2 | 0
3 | 1
4 | 2
5 | 4
6 | 4
我想一个脚本,可以返回一个特定客户的所有子ID的表。例如
get_child_ids (1) = 1,3
get_child_ids(2) = 2,4,5,6
get_child_ids(3) = 3
get_child_ids(4) = 4,5,6
get_child_ids(5) = 5
get_child_ids(6) = 6
某些ID可能会上升到10级。我发现了一个很好的解决方案,可以在https://explainextended.com/2009/07/20/hierarchical-data-in-mysql-parents-and-children-in-one-query/上获得父母ID,但是我很难找到孩子
什么麻烦? id的数据与您共享示例数据中的其他id不同。 –