表的递归查询
想写个存储过程,实现以下类似的功能
ID father Mother Birthday
01 -1 -1 2000
02 -1 -1 2000
03 01 02 2010
04 01 02 2011
05 01 03 2014
06 05 04 2015
输入id,能够检索出他所有的族谱信息,包括母系,和父系的所有信息
!
麻烦,谢谢!
问题点数:20、回复次数:2Top
1 楼lilu207(lilu)回复于 2005-06-12 13:27:11 得分 20
select ID,father,Mother,Birthday
from yourtable
where ID=值
union
select ID,father,Mother,Birthday
from yourtable
where father=(select father from yourtable where ID=值)
union
select ID,father,Mother,Birthday
from yourtable
where Mother=(select Mother from yourtable where ID=值)
不知道这样能实现不?Top
2 楼speedy(小明)回复于 2005-06-13 12:56:22 得分 0
不能的,是要检索出母系的所有,父系的所有,譬如父亲的父亲,父亲的母亲等等,整个族谱出来
Top




