count fields over multiple rows

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • griemer

    #1

    count fields over multiple rows

    I have a database like this

    id, field1,field2,f ield3,field4,fi eld5

    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).......... ..........+(num ber of fields filled in row100)

    Thanx
    Griemer

  • Bill Karwin

    #2
    Re: count fields over multiple rows

    griemer wrote:[color=blue]
    > I have a database like this
    >
    > id, field1,field2,f ield3,field4,fi eld5
    >
    > 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?[/color]

    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

    Regards,
    Bill K.

    Comment

    Working...