如何按名称对查询进行分组? P_Name

问题描述 投票:-2回答:1
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子句的结果:

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
sql asp.net
1个回答
0
投票

我想你想添加“PARTITION BY”

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
© www.soinside.com 2019 - 2024. All rights reserved.