Jump to content

Sum a column using specific values

Recommended Posts

I am trying to sum a column from a qurey using the top values only. Using the following line I get the result ( 7 top distance answer) for that column. $distance = mysql_query("SELECT distance FROM competition WHERE JPersonID=$row[iD] ORDER BY distance DESC LIMIT 7"); $row[iD] is from an earlier query so that only values related to the above query is called. As can be seen I order the result from highest to lowest limiting the result to 7 records. Now I need to add these results, to get a total distance. Using the 'SUM(distance) As xxx' does not give me the right result in the above query. (It counts all the distances relating to $row[iD]. I only require the top 7 results. Please can someone help? The result displayed should be as follows: (The code for this is not required. I just need to know how to sum the 7 jumps using the query) Total Distance Jump 1 Jump 2 Jump3 Jump4 Jump5 Jump6 Jump7 32.4 5.4 5.3 5.1 4.8 4.5 3.9 3.4

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...