2017-08-15 86 views
0

如何將query1的結果分配給query2? (結果有小數點)謝謝: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

不要比較字符串,使簡單的'where counter_date sysdate-1和sysdate - 1/24'之間, TRUNC(sysdate - 1,'MI')和TRUNC(sysdate - 1/24,'MI')之間的TRUNC(counter_date,'MI')' –

回答

0

你可以簡單地這樣做:

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 

(或副如果你的意思是另一種方式)。

謹防被零除錯誤!