获取具有值的列的百分比

I tried to do this:

 SELECT (SELECT COUNT(*)
 FROM users WHERE email != '') / (SELECT COUNT(*) FROM users)

But it gave me this error in php Operand should contain 1 column(s), in mysql everything works. Any other solution?

EDIT : its not exactly like that I had also groups by months, the above query works but the accepted answer solves my error

You can do it in a single query:

SELECT SUM(email != '') / COUNT(*) 
    AS ratio
  FROM users

... or, if you need percentage:

SELECT 100 * SUM(email != '') / COUNT(*)
    AS percentage
  FROM users

try this..

SELECT (SELECT COUNT(your_primary_key) FROM users WHERE email != '') / (SELECT COUNT(your_primary_key) FROM users)....

this is happening due to number of fields are different in both tables...

try this:

 SELECT COUNT(*) as counts
 FROM users 
 WHERE email != '' 

What do you want to do? If you can calculate the percentage in SQL query, you may follow the link Calculating Percentage within MYSQL query based on conditions