Division using Counts in Oracle SQL -
basic question, trying division sql statements return single value.
i want number of rows value less 40 in 'random_num' column divided total number of rows keep getting error. mind pointing out how this/
select count() / ( select count () abc) abc random_num < 40
create table abc (continent varchar2(30), country varchar2(30), random_num number, yr number) insert abc values ('asia', 'india', 50, 2005) insert abc values ('asia', 'japan', 100, 2006) insert abc values('asia', 'korea', 35, 2007) insert abc values ('asia', 'china', 200, 2008)
a simple way use case
count rows value < 40;
select count(case when random_num < 40 1 end)/count(*) ratio abc
Comments
Post a Comment