Mongow
Mongow

Reputation: 69

How to calculate percentage with a Oracle SQL statement with two tables

How to calculate percentage with a Oracle SQL statement with two tables?

Why this sql code below doesn't work ?

select sum( count(*) / (select count(*) from przedmioty) )*100 from przedmioty 
where id_prz NOT IN (select id_prz from transakcje);

I want to count how many percent of the rows in the table "przedmioty" is not on the table "transakcje" (based on "id_prz").

Upvotes: 3

Views: 8185

Answers (1)

Randy
Randy

Reputation: 16673

maybe something like this:

select (n/c)*100 pct
from ( select count(*) c from przedmioty ) 
, ( select count(*) n from przedmioty 
    where id_prz NOT IN (select id_prz from transakcje));

Upvotes: 2

Related Questions