选择直到在MySQL中

时间:2018-08-22 19:07:08

标签: mysql sql loops do-while

我有此表,其中包含user_idfather_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

0 个答案:

没有答案