Ben_Coding
Ben_Coding

Reputation: 408

SQL (Oracle) -How to Get Ratio from two Count Statements?

I want to get the Ratio of count1 / count2
which gives me percent compliant. this is right beneath my finger tips...
Can I get some help?

Select 
 (
 Select Count (*) from tso_skf_nomeas_in60days_v 
 ) as count1, 
 (
 Select Count (*) from tso_skf_recent_meas
 ) as count2
 (
 from dual

Upvotes: 4

Views: 8140

Answers (3)

Ben_Coding
Ben_Coding

Reputation: 408

Updated Answer:

Select Count1/Count2
FROM (Select Count(*) Count1 From tso_skf_nomeas_in60days_v) tso_skf_nomeas_in60days_v,
(Select Count(*) Count2 From tso_skf_recent_meas) tso_skf_recent_meas;

as see on SQL Fiddle.

Final Results:

enter image description here

Upvotes: 1

Mike Monteiro
Mike Monteiro

Reputation: 1457

SELECT
(SELECT cast(COUNT(*) as float) FROM tso_skf_nomeas_in60days_v)
/
(SELECT cast(COUNT(*) as float) FROM tso_skf_recent_meas) as perc
FROM dual

Upvotes: 2

sgeddes
sgeddes

Reputation: 62841

You're pretty close:

Select 
    (Select Count (*) from tso_skf_nomeas_in60days_v) 
    / 
    (Select Count (*) from tso_skf_recent_meas) as perc
from dual

SQL Fiddle Demo

Upvotes: 6

Related Questions