Hello, in mysql, how do you count the non empty cells in one row? And I want to count the cells between certain columns only, say between columns 3-10. not all the columns... again, in that row only.

    ketanco;10889580 wrote:

    Hello, in mysql, how do you count the non empty cells in one row? And I want to count the cells between certain columns only, say between columns 3-10. not all the columns... again, in that row only.

    $sql="SELECT COUNT (id) AS rows_count,* FROM table where field1 NOT NULL";

    with the Where part you could add the parameters you want to choice.
    But add those field's name in tehe SQL query. Test the $sql string before use in phpmyadmin.

    Let's read a mysql reference

      All I can think of using a bunch of IF()'s and adding them together:

      SELECT IF(col1 IS NOT NULL, 1, 0) + IF(col2 IS NOT NULL, 1, 0) + IF(col3 IS NOT NULL, 1, 0) AS non_empty 
      FROM table . . .
      

      If a column should be counted as empty if it's an empty string (instead of actually NULL), then you would have to make it even uglier with:

      IF(col1 IS NOT NULL AND col1 != '', 1, 0)
        Write a Reply...