I have a table user with column data which has most of the fields empty so it is basically NULL. I want to count the no: rows with data present in that column.
ONE WAY : So I thought I could count the no: NULL fields and subtracts from the total row.
ANOTHER WAY: I could directly count the occupied fields( but which i apparently don’t know). So I wrote this for the 1st method….but the count it gives is 0. It is not able identify the NULL or whatever.
$sql = "SELECT COUNT(CASE WHEN data = '' THEN 1 END) AS null_count, FROM users";
$real= mysql_query($sql);
while($row = mysql_fetch_assoc($real)) {
echo "null Count: {$row['null_count']}". '<br />';
}
1 Answer