Reputation: 17
Good afternoon, can you help me?
I have a table of "routes" Me need calculate count all routes, and count routes with "where". And % two from one.
For example:
select count(routes) from table1
"~ 150000 items"
select count (routes) from table1 where distance < 100
"~ 15000 items"
How to get a number 10%?
Upvotes: 0
Views: 43
Reputation: 769
Try this:
select count(CASE WHEN distance < 100 THEN 1 ELSE 0 END)/count(routes)*100 from table1 where distance < 100
Upvotes: 0
Reputation: 142958
You could conditionally aggregate values:
select sum(case when distance < 100 then 1 else 0 end) /
count(*) * 100 as result
from table1;
Or (worse), use current queries as subqueries:
select
(select count(routes) from table1 where distance < 100) /
(select count(routes) from table1) * 100 as result
from dual;
Upvotes: 1