SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    273
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get sum of scores where option1=option2 (was "please help fast....")

    i have a table

    id questionno. option1 score option2



    now 30 rows woudl be inserted into this....i need to get THE SUM OF THE SCORES of only those rows where option1 IS EQUAL TO option2

    please help me php and mysql being used

    please help

  2. #2
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT SUM(score) WHERE option1 = option2

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GoldFire
    SELECT SUM(score) WHERE option1 = option2
    You mean
    Code:
    SELECT SUM(score) FROM table WHERE option1 = option2
    I think.

  4. #4
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, it was late and I forgot the FROM part

  5. #5
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just to add my 2cents, and not that it changes the result, but I always found it easier to name the resultant of queries like this.
    PHP Code:
    $result mysql_query("SELECT SUM(score) AS mysum FROM table WHERE option1=option2");
    echo 
    mysql_result($result0"mysum"); 

  6. #6
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,423
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    If you want fast help use a better title for your thread. Many people skip threads with title slike "help" and "urgent". I know I do. I only stop by to report them and hopefully get the title changed.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes you better should titled your thread
    i agree with stymiee
    PR6 Web Directory

    PR5 Category and Subcategory Pages

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,250
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    thanks for reporting, i'm not usually in the php forum but i'm happy to rename a thread when the report comes in and i'm the first moderator to get to it

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •