我有这两个查询。
计算为空的电子邮件计数
SELECT COUNT(*) as invalid_email FROM distinct_customers WHERE c_email IS NULL;
计算每封电子邮件的数量
SELECT COUNT(distinct c_number) as total FROM distinct_customers;
我正在尝试将其与查询结合起来,以便给我一定百分比的有效电子邮件(不为null)
我尝试了几种方法,但我不是mysql专家。
数学上应该是
643(空电子邮件)* 100/1292(总电子邮件)
SELECT AVG(c_email IS NOT NULL) as invalid_email_ratio,
100 * AVG(c_email IS NOT NULL) as invalid_email_perentile
FROM distinct_customers ;
SELECT (COUNT(case when c_email IS NULL then 1 end)*100.00)/
COUNT(distinct c_number) as percentage
FROM distinct_customers