[英]MySQL sum of query result
I have a table called "trails" inside the table I have 3 columns called "id", "name" and "grading". 我在表内有一个名为“ trails”的表,我有3列分别称为“ id”,“ name”和“ grading”。
I have the following query which gives me the last 5 rows of a specific trail name based on the id. 我有以下查询,该查询根据ID为我提供了特定跟踪名称的最后5行。 This works perfectly but now I need to get the sum total of the 5 results in the grading column?
这可以完美地工作,但是现在我需要在等级列中获得5个结果的总和?
SELECT * FROM `trails` WHERE `name` = "Free Flow" ORDER BY `id` DESC LIMIT 5
SELECT sum(`grading`)
FROM
(SELECT *
FROM `trails`
WHERE `name` = "Free Flow"
ORDER BY `id` DESC LIMIT 5) AS TEMP;
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.