SQL总计数除以总计数

below table is the data :

for example table name 'Status'

no.-User_status

1 -exec

2 -exec

3 -exec

4 -init

5 -init

6 -aware

7 -aware

8 -pend

9 -pend

10-pend

my question is, how to count total of 'user_status' and divide by total of user_status 'exec' ?

what i have so far, is to calculate total number of user_status only, but i couldn't divide such thing i stated above or is there any way i could do that?

SELECT count(user_status),

FROM Status

Try this

select user_status, count(*)/(select count(*) from Status where user_status='exec')
from Status
where exists (select 1 from Status where user_status='exec')
group by user_status

note that if there are no execs the quotient is undefined.

Something like this should work:

select numerator / denominator theanswer
from (
select count(*) numerator
, sum(case when user_status = 'Exec' then 1 else 0 end) denominator
from status
) temp
where denominator > 0