如何实现找上游的功能?

WBOY
Release: 2016-06-23 13:18:00
Original
933 people have browsed it

各位大神我的MYSQL数据库大概是这样的结构:
USER PUSER
16   
24             16
19            16
21             24
32           19


我想实现以下查询功能,设定初始值后,就能把其每一级的上游都找出来,如初始值为32:则查出:32-19-16

而如果初始值为21时,就是21-24-16

而如果初始值为24时,就是24-16

我该怎么办呢?有好办法么?


回复讨论(解决方案)

递归,就是最基础的算法

哥,你知道我的,怎么递归?我不懂啊,有没有一些标准化的语句啊?谢谢!

这类一般用递归算法实现。
http://baike.baidu.com/link?url=x0R_sYh7508JGV4zKDTCPVkOCqP_J9YtFD9Pp6CfGt-5Y-DnIaamAX472qHrZAXqo06CuAsruW1TqmLduxz0na

还是没没学会啊

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template