我有此表,其中包含user_id
和father_id
。
我想选择与father_id
关联的所有user_id
,直到father_id = 0
的值,然后以逗号分隔的格式存储它们。
表格:network
select user_id, father_id from network where user_id = 1762;
user_id father_id
1762 1761
select user_id, father_id from network where user_id = 1761; -- resulting father_id from the first query
user_id father_id
1761 1760
select user_id, father_id from network where user_id = 1760; -- resulting father_id from the second query
user_id father_id
1760 0
在此示例中,我想通过使用所得的father_id
作为father_id = 0
来获取所有father_id
直到我到达next user_id
。