Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MS Access SQL中获取总金额?_Sql_Database_Ms Access - Fatal编程技术网

如何在MS Access SQL中获取总金额?

如何在MS Access SQL中获取总金额?,sql,database,ms-access,Sql,Database,Ms Access,我使用以下查询获取OrderID: SELECT OrderItem.ID , ProductID , OrderID , Quantity , P.Title , P.CurrentPrice , P.ID , (P.CurrentPrice* OrderItem.Quantity) AS Total FROM OrderItem INNER JOIN Product AS P ON OrderItem.Product

我使用以下查询获取OrderID:

SELECT OrderItem.ID
     , ProductID
     , OrderID
     , Quantity
     , P.Title
     , P.CurrentPrice
     , P.ID
     , (P.CurrentPrice* OrderItem.Quantity) AS Total
FROM OrderItem
INNER JOIN Product AS P
   ON OrderItem.ProductID = P.ID

如何获取每个OrderID的总金额(使用相同OrderID添加所有总额)?

您可以使用选择表单进行选择和分组

select OrderID, sum(Total) 
from (
SELECT 
    OrderItem.ID
    , ProductID
    , OrderID
    , Quantity
    , P.Title
    ,P.CurrentPrice
    , P.ID
    , (P.CurrentPrice* OrderItem.Quantity) AS Total
FROM OrderItem 
INNER JOIN Product AS P ON OrderItem.ProductID = P.ID
) t 
group by OrderId 

我只是SQL新手,但我认为这就是解决方案

SELECT OrderItem.ID, ProductID, OrderID, Sum(Quantity) AS Sum of Quantity, P.Title,P.CurrentPrice, P.ID, (P.CurrentPrice* OrderItem.Quantity) AS Total
FROM OrderItem INNER JOIN Product AS P ON OrderItem.ProductID = P.ID GROUP BY OrderID

希望这有帮助。

提示:
分组依据
SUM()
。选择OrderItem.ID,ProductID,OrderID,数量,p.Title,p.CurrentPrice,p.ID,(p.CurrentPrice*OrderItem.Quantity)作为总计,来自OrderItem内部的总和(Total)将产品作为p加入OrderItem.ProductID=p.ID分组依据OrderID,OrderItem.ID,ProductID,Quantity,p.Title,P.CurrentPrice,P.ID不工作,输出所有记录和总和(Total)=Total我尝试在MS Access查询中使用其他查询的源,它工作按OrderID从MainQuery组中选择OrderID,总和(MainQuery.Total),但我需要使用Delphi和sql查询。非常感谢。如何使用SELECT O.ID、C.SecondName、E.SecondName、O.DateOf、O.ClientID、O.EmployeeID、O.Desc FROM((客户机作为C内部联接[ORDER]作为O ON C.ID=O.ClientID)内部联接员工作为E ON E.ID=O.EmployeeID)内部联接产品作为P ON P.ID=O.ProductID;对于Order表中的total字段?您的评论似乎是一个新问题。。。你应该发布一个新的记录良好的问题。。查看注释中的代码很难理解您的目标。。无论如何,如果我可以问我的权利,请标记为接受,并最终评论我的新链接