How to count non-empty cells in one row In MySQL
Posted by Raj
How to count non-empty cells in one row in MySql.
In this section, I will explain how to count non-empty cells in one row in MySql.
Suppose we have to count non empty cells of Price table.
Price table:
Col1 Col2 Col3
1000000 200 1000
4545556 400 NULL
Query:
SELECT IF(col1 IS NOT NULL, 1, 0) + IF(col2 IS NOT NULL, 1, 0) + IF(col3 IS NOT NULL, 1, 0) AS total_price
FROM price_table
This query will return Total price of non empty cells(col1,col2,col3)
This entry was posted on October 4, 2009 at 12:14 pm, and is filed under
count non empty cells,
count null cells within columns php sql,
mysql,
mysql count non empty fields in row,
PHP,
sql php count not null fields
.You can leave a response, or trackback from your own site.