设计一个表来表示父子关系,FatherSon(FatherID,SonID)
如系表为
father 1
son 2, 3, 4
grandson 5,6 7,8,9,10
表存储为:
1,2
1,3
1,4
2,5
2,6
3,7
3,8
3,9
3,10
这样,你就可以使用该表了
如找1的儿子
select SonID
from FatherSon
where FatherID=1
如果你找2的兄弟
select SonID
from FatherSon
where FatherID=(select FatherID
from FatherSon
where SonID=2) and
SonID<>2
如果你1找孙子
select b.SonID
from FatherSon a,FatherSon b
where a.FatherID=1 and
a.SonID=b.FatherID
你看,不是一样可以完成