Help in SQL ORACLE query

Asked

Viewed 76 times

0

Tabela no banco de dados oracle

Column DEPENDENCY: T - Titular; E - Esposa; F - Filhos; FA - Filho Adotivo

As table above, how do I bring data only of CEP S that are divergent as the CEP of the Holder:

Titular Admilson has 2 children with different zip code, as well as titular Marcelo.

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

1 answer

2


You can do it like 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;
  • Igor, thanks for the help, but this select brought 5 equal records of each holder, not bringing the holder and dependents with divergent strains.

  • I think you just switch the columns of select. I edited the answer. See if it now works.

  • Igor, I did this but it’s bringing in data of holders who do not belong to the family.

  • I edited the answer again. I could post (comment) the SQL result?

  • Igor, it worked out, thank you very much, I put a filter in the records that were disabled and the select worked perfect. Thanks!!

  • Cool guy! I’m glad I helped. If you think the answer solved the problem could mark as solution, please?

  • 1

    Sure, marked and again, thank you very much.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.