Help in SQL query ORACLE

0

Dependency column: T - Holder; And wife; F - Children; FA - Adoptive Son

As per table above, how do I bring data only from ZIP codes that differ from Zip Code:

  

Owner Admilson has 2 children with a different cp, as well as   holder Marcelo.

Abusing a little more, is it possible to bring the data of the holder and below the data of the children with the divergent ceps?

    
asked by anonymous 13.06.2017 / 22:47

1 answer

2

You can do this:

select
    tabela.familia as familia_titular,
    nao_titular.familia as familia_nao_titular,
    tabela.nome,
    nao_titular.nome,
    nao_titular.cep
from
    tabela,
    (
        select 
            familia,
            cep
        from 
            tabela 
        where
            dependencia <> 'T'
    ) as nao_titular
where
    tabela.familia = nao_titular.familia
    and tabela.dependencia = 'T'
    and tabela.cep <> nao_titular.cep;
    
14.06.2017 / 14:57