我在mysql中需要分层查询

时间:2015-10-16 05:32:43

标签: mysql

在mysql中需要分层查询。引入他人记录的人以及由他们介绍的所有其他人。请帮我。

 | associate_id  |  associate_introducer_id  |
 +---------------+---------------------------+
 |  123          |   999999999               |
 |  234          |   123                     |
 |  456          |   123                     |
 |  431          |   234                     |
 |  567          |   456                     |

如果用户输入123,那么123引入的所有记录显示以及子记录。

1 个答案:

答案 0 :(得分:0)

你的问题不清楚。也许你想用associate_introducer_id将具有相同id的所有记录更新为另一个id?

UPDATE your_table_name 
SET associate_introducer_id = '1234' 
WHERE associate_introducer_id = '123'