count fields over multiple rows

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have a database like this

id, field1,field2,field3,field4,field5

Database contains 100 rows, some rows  have no fields filled, some
1field , some 2 fields etc.

How would i count the number of fields filled in total?

So the outcome is (number of fields filled in row1)+(number of fields
filled in row2)+(number of fields filled in
row3)....................+(number of fields filled in row100)


Re: count fields over multiple rows

griemer wrote:
Quoted text here. Click to load it

The COUNT() aggregate function ignores NULLs (unless you use COUNT(*)).
  I assume that by "filled" you mean non-NULL, while a field not filled
has a NULL state.

SELECT COUNT(field1) + COUNT(field2) + COUNT(field3)
   + COUNT(field4) + COUNT(field5)
FROM myTable

Bill K.

Site Timeline