|
|
本帖最后由 spiral 于 2013-4-3 17:51 编辑
在oracle下,使用start with connect by prior即可- select * from t_user start with id = '11e1-7f98-dc0c84d6-a04d-05b43c063ac2' connect by prior id = superior
复制代码 在sqlserver下,只能使用存储过程完成,大致代码见下:- with cte as
- (
- select *, 0 as lvl from t_user
- where Id = '11e0-4b86-4e2e6951-a06c-ade030ea555d'
- union all
- select d.*,lvl + 1 from cte c inner join t_user d
- on c.Id = d.superior
- )
- select * from cte
复制代码 在mysql下,只能使用存储过程以及递归完成,大致可以参考下帖:
http://blog.csdn.net/ACMAIN_CHM/article/details/4142971 |
|