SQL |
select a.animal_id, c.ebv from animal a, cbv c
where c.animal_id = a.animal_id and
c.ebv_type in ( 0, 1 ) and c.trait_cd = 'CIndx' and
a.breed_cd = 'AI' and a.sex_cd = 'M' and
( a.logo = 'C' or a.animal_id in
( select animal_id from aka where
animal_id = a.animal_id and logo = 'C' ) ) and
( exists ( select 1 from animal p, aka x where
p.animal_id = x.animal_id and p.sire_id = a.animal_id and
p.birth_date > date('today') - date('2 years') and
( p.logo = 'C' or x.logo = 'C' ) ) or
a.birth_date > date('today') - date('2 years' ) )
order by ebv desc |