Jump to content

Need some help with a query please, counting fields...


mikeee

Recommended Posts

Hi, I did so much research and still cant find the answer to this. I want to count how many fields are left empty in a table. But not all, just specific fields.

 

I have a USERS table, and I just want to count the profile related fields in that table that are left blank. If anyone can help me I would really appreceate it! thanks.

 

I tried to SELECT COUNT from TABLEX where field1='' and field2='' and userid=X

 

No go :(

Ok, well if you want to do a count, you probably shouldn't have the "and userid=X" at the end since you'll only have 1 record. 

 

This query will help you get a little more detail. I'm assuming you are not allowing nulls. If so, you need to take those into account as well.

SELECT
COUNT(*) AS num_users,
SUM(IF(field1 = '' AND field2 = '', 1, 0)) AS one_and_two,
SUM(IF(field1 = '', 1, 0)) AS empty_one,
SUM(IF(field2 = '', 1, 0)) AS empty_two
FROM users

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.