Reputation: 1
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
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
Reputation: 18600
SELECT sum(`grading`)
FROM
(SELECT *
FROM `trails`
WHERE `name` = "Free Flow"
ORDER BY `id` DESC LIMIT 5) AS TEMP;
Upvotes: 2