题解 | 宠物猫繁育族谱追溯与遗传病风险评估

宠物猫繁育族谱追溯与遗传病风险评估

https://www.nowcoder.com/practice/b81457c7327e4a17960804f3ef1a4fd3

with recursive descendant_tree as(
select child_cat_id as descendant_id
,1 as generation
,health_score
from breeding_records 
where parent_cat_id = (select cat_id from cats where cat_name='Luna')
and year(birth_date) = '2025'

UNION ALL

select br.child_cat_id
,dt.generation+1 generation
,br.health_score
from descendant_tree dt inner join breeding_records br
on dt.descendant_id=br.parent_cat_id 
where year(br.birth_date) = '2025'

)
select dt.descendant_id
,c.cat_name descendant_name
,dt.generation generation
,round(dt.health_score*pow(0.95,dt.generation),2) composite_index
from descendant_tree dt
left join cats c on dt.descendant_id=c.cat_id
order by generation asc ,composite_index desc,descendant_id asc

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务