sql oracle query to subtract two fields

0

Good, I've put the original querys that I'm going to use to give you an idea of the real problem, I need to subtract the values that return these two queries and do it all in the same query, that is, in the same query retrieve both values and then in the same query subtract them. a query would be:

select count(*)  from ( select rownum  rnum from all_objects where rownum <= last_day(to_date('29/07/2016','dd/mm/yyyy')) - to_date('29/07/2016','dd/mm/yyyy')+1 )
where to_char( to_date('29/07/2016','dd/mm/yyyy') +rnum-1, 'DY' ) not in ( 'SAT', 'SUN' )

and another would be:

select count(*) from T0GCDFES where trunc(fhdiafes)<=trunc(LAST_DAY(to_date('16/11/2016','dd/mm/yyyy')))
and trunc(fhdiafes)>=to_date('16/11/2016','dd/mm/yyyy') and cdcalend='CIG'

I want in a single query sql oracle subtract the two values that both queries return, that is, type (query1)-(query2) .

Exact queries are those, forgive that I have not been able to put them up until now, those two queries return each one a value, for example the first query returns me:

dias_laborables : 8

and the second:

dias_festivos: 2

I want a query that returns the subtraction of 8 - 2 = 6 , but I need in a single query to do the two queries that I put and the subtraction of the two fields that I returned, I do not know if I explain

    
asked by elvega 18.11.2016 в 19:23
source

1 answer

4

Since, as is clear from your question

  • both tables have a single record
  • both fields are numeric

You can perform the subtraction directly like this:

select a.dias_laborables - b.dias_festivos resultado
  from TABLADIAS a
       cross join TABLADIFE b
    
answered by 18.11.2016 в 19:32