How to calculate the value of two subquery in Oracle SQL

Asked

Viewed 67 times

0

How to calculate two subquery on Oracle?

Could you explain to me how I sum up VALOR_1 + VALOR_2?

SELECT COL1
, (SELECT SUM(TAB1.VLRTOTAL)
    FROM TABELA TAB1
    WHERE TAB1.ID = TAB3.ID) AS VALOR_1

, (SELECT SUM(TAB2.VLRTOTAL)
    FROM TABELA2 TAB2
    WHERE TAB2.ID = TAB4.ID) AS VALOR_2

FROM TABELA3 TAB3, TABELA4 TAB4
WHERE TAB4.ID = TAB2.ID
AND TAB2.ID <= 10

2 answers

1


Try to perform a subselect of that information:

select dados1+dados2
  from (Select (select seuselectdados1) as dados1
             , (select seuselectdados2) as dados2
          from table
      ) as tab_temp

0

Thanks to the cooperation of all, more I solved in this way:

Thank you very much.

, (SELECT NVL(SUM(TAB1.VLRTOTAL),0)
    FROM TABELA TAB1
    WHERE TAB1.ID = TAB3.ID) AS VALOR_1

, (SELECT NVL(SUM(TAB2.VLRTOTAL),0)
    FROM TABELA2 TAB2
    WHERE TAB2.ID = TAB4.ID) AS VALOR_2

, (SELECT NVL(SUM(TAB1.VLRTOTAL),0)
    FROM TABELA TAB1
    WHERE TAB1.ID = TAB3.ID)+
, (SELECT NVL(SUM(TAB2.VLRTOTAL),0)
    FROM TABELA2 TAB2
    WHERE TAB2.ID = TAB4.ID) AS AS SOMATOTAL


FROM TABELA3 TAB3, TABELA4 TAB4
WHERE TAB4.ID = TAB2.ID
AND TAB2.ID <= 10

Browser other questions tagged

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