如何对内部查询的值求和

时间:2019-04-17 13:47:12

标签: sql

我有一个查询可以解决表达式并显示3个数字。我该如何求和这些数字,因为它们与表的任何列都不相关

以下是查询:

SELECT 
    (Gramms * DishCost / 100) AS PRICE
FROM 
    Portion 
INNER JOIN 
    Zakaz ON Portion.ID_Portion = Zakaz.ID_Portion
INNER JOIN 
    Dishes ON Dishes.ID_Dishes = Portion.ID_Dishes

返回

none
6
6
75

我该如何对这三个数字求和以获得87?

2 个答案:

答案 0 :(得分:0)

使用sum()

SELECT sum((Gramms*DishCost/100)) AS PRICE
FROM Portion INNER JOIN Zakaz ON Portion.ID_Portion = Zakaz.ID_Portion
INNER JOIN Dishes ON Dishes.ID_Dishes = Portion.ID_Dishes

答案 1 :(得分:0)

在查询中添加sum()聚合函数

SELECT sum((Gramms*DishCost)/100) AS PRICE
FROM Portion INNER JOIN Zakaz
ON Portion.ID_Portion = Zakaz.ID_Portion
INNER JOIN Dishes
ON Dishes.ID_Dishes = Portion.ID_Dishes