2017-08-15 3 views
0

Wie kann ich das Ergebnis von Abfrage1 zu Abfrage2 teilen? (. Das Ergebnis hat Dezimalpunkte) Danke:Frage Division in Oracle

query1:

select count(*) as aa 
    from registered_devices 
where status = 1; 

query2:

select sum(last_count) as current_daily 
    from statistics    
where to_char(counter_date, 'YYYYMMDDHH24') between to_char (sysdate - 1, 'YYYYMMDDHH24')      
    and to_char (sysdate - 1 /24, 'YYYYMMDDHH24') 
    and counter_type = 'WS_GET_OFFER_ACCEPT' 
+1

Vergleiche keine Strings miteinander, mache einfach 'where counter_date zwischen sysdate - 1 und sysdate - 1/24' bzw. 'wo TRUNC (counter_date, 'MI') zwischen TRUNC (sysdate - 1, 'MI') und TRUNC (sysdate - 1/24, 'MI')' –

Antwort

0

Sie können dies einfach tun:

select (select count(*) as aa 
      from registered_devices 
     where status = 1) 
    /(select sum(last_count) as current_daily 
      from statistics    
      where to_char(counter_date, 'YYYYMMDDHH24') 
        between to_char (sysdate - 1, 'YYYYMMDDHH24')      
         and to_char (sysdate - 1 /24, 'YYYYMMDDHH24') 
       and counter_type = 'WS_GET_OFFER_ACCEPT') 
    from dual 

(oder umge Umgekehrt, wenn Sie den anderen Weg gemeint haben).

Vorsicht vor Fehler durch Division durch Null!