SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: SUM Question

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SUM Question

    I'm trying to sum the results of a field generated from adding 2 fields in my database.

    For example I take field A + field B = Field C

    Now I want to sum all the results of field C.

    I know how to SUM the fields that are already in my database.

    example:
    $r1 = mysql_query("SELECT SUM(field) FROM Table");

    but what I want to do is SUM a field that is created from the results of Field A + Field B.

    I'm sure this is easy, but for some reason can't get it done.

    Thanks for any help.

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i created a table with field
    a - tinyint
    b - tinyint

    and the values

    a - b
    1 - 2
    3 - 4

    and i did
    select sum((a+b)) from table
    and it gave me 10
    is this what you want. i never did this before. so i just made an example and tried this and it worked.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    i created a table with field
    a - tinyint
    b - tinyint

    and the values

    a - b
    1 - 2
    3 - 4

    and i did
    select sum((a+b)) from table
    and it gave me 10
    is this what you want. i never did this before. so i just made an example and tried this and it worked.
    I think that might work, i'll give it a shot. What I want is..using your example.

    a : b = c (a result from adding database columns a + b)
    1 : 2 = 3
    3 : 4 = 7

    So basically i'm trying to sum up column c, which I think your above example should do.

    Thanks for the help, i'll give it a shot.

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2002
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way that worked like a charm.

    Cheers.


Bookmarks

Posting Permissions

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