我在SQL中有两个名为var categoriesToSort = []; //categoriesToSort has some values
var sortedCategories = new Map();
for(var j = 0 ; j < categoriesToSort.length ; j++) {
categories.forEachMap(function(key, value){
if(categoriesToSort[j] === value) {
sortedCategories.set(key, value);
}
});
}
和tblFolding
的表。在tblStockManagement
我有tblFolding
和FoldingID
列。在Price
我有tblStockManagement
(来自FoldingID
的外键)和tblFolding
。
我想要的是计算Quantity
中可用的项目数量的Total Price
,但tblStockManagement
来自Price
表。我正在尝试这个,但我不知道确切的查询。请帮助我。
答案 0 :(得分:3)
这可能会有所帮助..
SELECT sum (b.Quantity*a.Price) as total price
FROM tblFolding a, tblStockManagement b
WHERE a.FoldingID = b.FoldingID
答案 1 :(得分:1)
这将通过折叠ID提供总价格
SELECT TF.FoldingID, SUM(TF.Price * SM.Quantity) AS TotalPrice
FROM tblFolding TF
INNER JOIN tblStockManagement SM ON SM.FoldingID = TF.FoldingID
GROUP BY TF.FoldingID
如果不希望通过折叠得到结果并期望整个总价,请尝试:
SELECT SUM(TF.Price * SM.Quantity) AS TotalPrice
FROM tblFolding TF
INNER JOIN tblStockManagement SM ON SM.FoldingID = TF.FoldingID
<强>更新强>
根据您的评论,我了解您希望根据FoldingID
表格中的tblStockManagement
获得结果。所以添加WHERE子句并按条件过滤。
SELECT TF.FoldingID, SUM(TF.Price * SM.Quantity) AS TotalPrice
FROM tblFolding TF
INNER JOIN tblStockManagement SM ON SM.FoldingID = TF.FoldingID
WHERE SM.FoldingID IN (1, 2, 3, 4) -- modify the condition as per your requirement
GROUP BY TF.FoldingID