Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Finding a Ratio (Dividing Two Columns that are not Numbers/Intergers)?

user11137889Nov 12 2009 — edited Nov 12 2009
Hi all,

I'm trying to find the male-to-female ratio in each department. The situation is empSEX is a VARCHAR2 datatype.
I need "M" / "F" as a new column.
SELECT Dept,
count(empID),
TO_NUMBER(count(case when empSEX = 'M' then 1 else null end)) M,
TO_NUMBER(count(case when empSEX = 'F' then 1 else null end)) F
FROM EMPLOYEE
WHERE Date=’200909’;
I'm not sure if I should be using the TO_NUMBER function instead of CONVERT or something else. Also, what happens when there are no females in a department, can't divide by zero?

As always any help will be greatly appreciated. Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2009
Added on Nov 12 2009
6 comments
1,189 views