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 :(

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.