Click to See Complete Forum and Search --> : how to count non empty cells in a row


ketanco
10-05-2008, 09:46 AM
how do you count non empty cells in a row in mysql? also, i only want to count a certain range of cells. not all. for example, my row is: id, title, date, q1, q2, q3, q4, q5, q6. I would like to count only the range of q1 through q6 and want to find how many of them are non empty. q1 through q6 are all text cells by the way - if it matters.

chazzy
10-05-2008, 10:56 AM
I think you want something like


select id,
CASE q1 WHEN NULL THEN '1' ELSE '0' END CASE as q1val,
... (repeat for q2-q6),
SUM(q1val,q2val,q3val,q4val,q5val,q6val) AS num_null
from your_group
group by id;