2016-11-11 47 views
-2
select ID_Sale,SaleDate,Branch_Name,P_Name,P_UnitPrice,QuantitySold, 
    sum (QuantitySold*P_UnitPrice) over (order by ID_Sale asc) AS RunningTotal 
from tblP_Sales 
INNER JOIN tblProduct_With_Img 
    ON tblP_Sales.P_ID_Sales = tblProduct_With_Img.P_ID 
INNER JOIN tblBranches 
    ON tblP_Sales.BranchID = tblBranches.BranchID 
--this group is not working ? how to work this ? 
    group by P_Name 

這是沒有GROUP BY條款的結果:我認爲你正在尋找增加 「PARTITION BY」如何按名稱對我的查詢進行分組? P_Name

Sale_ID Sale_Date Branch Item Name     Pric/unit qty RUNTotal 

1056 2016-11-10 Ajman Afghani Pulaw With Meat  26  1 26 
1057 2016-11-10 Ajman Sada Rice With Chicken Boti 24  2 74 
1058 2016-11-11 Ajman Afghani Pulaw With Meat  26  1 100 
+3

代碼唯一的問題是很難回答。請看看http://stackoverflow.com/help/how-to-ask – HoneyBadger

+0

請再解釋一下你的問題。你指的是哪個'名字'('Branch_Name','P_Name',還有別的東西)?請儘可能提供示例數據。 – sr28

+0

相同的查詢只是由P_Name(Product_Name) –

回答

0

select ID_Sale,SaleDate,Branch_Name,P_Name,P_UnitPrice,QuantitySold, 
    sum (QuantitySold*P_UnitPrice) over (PARTITION BY P_Name order by ID_Sale asc) AS RunningTotal 
from tblP_Sales 
INNER JOIN tblProduct_With_Img 
    ON tblP_Sales.P_ID_Sales = tblProduct_With_Img.P_ID 
INNER JOIN tblBranches 
    ON tblP_Sales.BranchID = tblBranches.BranchID 
+0

分組它是好的爲P_Name做一個組我想組P_Name(產品名稱) –

相關問題