sum columns in same row
Results 1 to 4 of 4

Thread: sum columns in same row

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    32

    sum columns in same row

    Hello all,

    I have the requirement to find the sum of a number of fields in one data row.

    In short I have the following:

    PHP Code:
    SELECT Seq01 Seq02+Seq03+Seq04  as ItemSum FROM Tablename 
    The issue I have is if one of the fields is null the query fails. How can I get around this?


    Any help would be great.

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,432
    Does "NULL" have special meaning for the fields? In other words, did you really mean to use NULL, or is a default value of 0 more appropriate?

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    32
    Hi Bradgrafelman,

    thanks for your reply.

    The fields would be "empty" of data.

    Many thanks

  4. #4
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,568
    Out of curiosity, but why do you have to sum across fields? I'm not saying that this is always wrong, but it tends to be a sign of poor relational database design, e.g., you have numbered fields that should have been separated into rows of a different table.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •