user1287814
user1287814

Reputation: 1

MySQL sum of query result

I have a table called "trails" inside the table I have 3 columns called "id", "name" and "grading".

I have the following query which gives me the last 5 rows of a specific trail name based on the id. This works perfectly but now I need to get the sum total of the 5 results in the grading column?

SELECT * FROM `trails` WHERE `name` = "Free Flow" ORDER BY `id` DESC LIMIT 5

Upvotes: 0

Views: 107

Answers (2)

user2473917
user2473917

Reputation: 1

you can use this query to get the sum of a particular column

SELECT SUM(originalOfferSize)
FROM `ActiveListings`
WHERE `originalOfferSize` = 4000000
ORDER BY `listingId` DESC LIMIT 5

Upvotes: -1

Sadikhasan
Sadikhasan

Reputation: 18600

SELECT sum(`grading`)
FROM
  (SELECT *
   FROM `trails`
   WHERE `name` = "Free Flow"
   ORDER BY `id` DESC LIMIT 5) AS TEMP;

Upvotes: 2

Related Questions