ALTER PROCEDURE [dbo].[K_RT_GetProdutstogrid]
@branch int
AS
BEGIN
SET NOCOUNT ON;
select PS.sno, PD.productname,sum(PS.quantity) as quantity,PS.description from
K_RT_PurchaseDet PS
inner join K_RT_ProductDetails PD on PD.sno=PS.product where purchasedby=@branch
and PS.company=@company and modelno=@modelno
group by PS.quantity,PS.sno, PD.productname,PS.description
END
当公司和modelno相同时如何计算数量
答案 0 :(得分:1)
尝试此操作,无需在GROUP BY中包含数量
ALTER PROCEDURE [dbo].[K_RT_GetProdutstogrid]
@branch int
AS
BEGIN
SET NOCOUNT ON;
select PS.sno, PD.productname,sum(PS.quantity) as quantity,PS.description from
K_RT_PurchaseDet PS
inner join K_RT_ProductDetails PD on PD.sno=PS.product where purchasedby=@branch
and PS.company=@company and modelno=@modelno and PS.company=modelno
group by PS.sno, PD.productname,PS.description
END