Skip to content
Advertisement

MYSQL Query calculate percentage of emails not null

I have these two queries.

Caluculates count of emails that are null

SELECT COUNT(*) as invalid_email FROM distinct_customers WHERE c_email IS NULL;

Calculates count of every email

SELECT COUNT(distinct c_number) as total FROM distinct_customers;

I am trying to combine those to queries so that it gives me a percentage of valid emails (not null)

I tried a couple of ways but I am not a mysql expert.

Mathematically it should be

643(null emails)*100 / 1292(total emails)

Advertisement

Answer

You can try below –

SELECT (COUNT(case when c_email IS NULL then 1 end)*100.00)/
        COUNT(distinct c_number) as percentage
FROM distinct_customers
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement