使用 SQL Server 2008。我有一个存储在表中的动物家谱,并想提供一些关于后代“遗传多样性”(或不具有)程度的信息。在 SQL 中,我如何生成合理的指标来显示父母之间的密切关系?也许某种百分比的共享血统,或者在有共同祖先之前要追溯到几代人?
AnimalTable
Id
Name
mumId
dadId
select * from AnimalTable child
inner join AnimalTable mum on child.[mumId] = mum.[Id]
inner join AnimalTable dad on child.[dadId] = dad.[Id]
inner join AnimalTable mums_mum on mum.[mumId] = mums_mum.[Id]
inner join AnimalTable mums_dad on mum.[dadId] = mums_dad.[Id]
inner join AnimalTable dads_mum on dad.[mumId] = dads_mum.[Id]
inner join AnimalTable dads_dad on dad.[dadId] = dads_dad.[Id]