MYSQL总和
我们需要计算每种产品的碳足迹。碳足迹基本上是每个元素的碳足迹与构成给定产品的每个元素百分比的乘积之和。 下面的代码是我们到目前为止的代码,但它不起作用,我们还尝试使用SUM(e.carbonfootPrint*c.percentage/100) 切勿在MYSQL总和,mysql,sql,database,sum,Mysql,Sql,Database,Sum,我们需要计算每种产品的碳足迹。碳足迹基本上是每个元素的碳足迹与构成给定产品的每个元素百分比的乘积之和。 下面的代码是我们到目前为止的代码,但它不起作用,我们还尝试使用SUM(e.carbonfootPrint*c.percentage/100) 切勿在FROM子句中使用逗号。始终使用正确、明确的JOIN语法 SELECT p.name, SUM(e.carbonfootPrint * c.percentage)/100 AS CarbonFootprintProdut FROM P
FROM
子句中使用逗号。始终使用正确、明确的JOIN
语法
SELECT p.name,
SUM(e.carbonfootPrint * c.percentage)/100 AS CarbonFootprintProdut
FROM Produt p JOIN
Element e
ON c.element = e.code JOIN
composed c
ON c.produt = p.code
WHERE p.tipo = 'lar'
GROUP BY p.name;
注:
表未使用,因此我将其删除brand
- 您需要对产品进行聚合,从而得到整个产品的总数
- 您需要一个
分组依据
- 使用正确的
语法JOIN
SELECT p.name,
SUM(e.carbonfootPrint * c.percentage)/100 AS CarbonFootprintProdut
FROM Produt p JOIN
Element e
ON c.element = e.code JOIN
composed c
ON c.produt = p.code
WHERE p.tipo = 'lar'
GROUP BY p.name;