Showing posts with label mysql count non empty fields in row. Show all posts
Showing posts with label mysql count non empty fields in row. Show all posts
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)