
이 ecoli_data table로만 각 id의 형질과 부모의 형질을 비교해야 한다.
두개의 다른 테이블을 join 하는 것보다 더 어려운 것 같다. 🥲

< 생각 하기 >
1) join 위한 조건 생각하기
2) join 후 추출조건 생각하기

select id, genotype as parent_genotype
from ecoli_data

with geno as (
select id, genotype as parent_genotype
from ecoli_data)
select e.id, e.genotype ,g.id, g.parent_genotype
from ecoli_data e
join geno g on e.parent_id = g.id
where ( e.genotype & g.parent_genotype) = g.parent_genotype
order by e.id
g.id는 잘 뽑혔나 확인용으로 찍어봤다.
with geno as (
select id, genotype as parent_genotype
from ecoli_data)
select e.id, e.genotype , g.parent_genotype
from ecoli_data e
join geno g on e.parent_id = g.id
where ( e.genotype & g.parent_genotype) = g.parent_genotype
order by e.id