本文介绍了如何根据条件组得到列的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! ALTER PROCEDURE [dbo]。[K_RT_GetProdutstogrid] @branch int AS BEGIN 设置NOCOUNT ON; 选择PS.sno,PD.productname,sum(PS.quantity)作为数量,PS.description来自 K_RT_PurchaseDet PS 内部联接K_RT_ProductDetails PD在PD.sno = PS.product,其中buyby = @ branch PS.quantity,PS.sno,PD.productname,PS.description END i想要在有很多行与同一公司和modelnoALTER 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.descriptionEND i want to sum quantity when there are many rows with same company and modelno推荐答案查询应该是这样的。您无需在 GROUP BY 子句中输入数量。列顺序应与 SELECT 子句相同。Query should be like this. You don't need to put quantity in GROUP BY clause. And columns order should be same as SELECT clause.ALTER PROCEDURE [dbo].[K_RT_GetProdutstogrid]@branch intASBEGINSET NOCOUNT ON;select PS.sno, PD.productname,PS.description,SUM(PS.quantity) as quantity fromK_RT_PurchaseDet PSinner join K_RT_ProductDetails PD on PD.sno=PS.product where purchasedby=@branchand PS.company=@company and modelno=@modelnogroup by PS.sno, PD.productname,PS.descriptionEND 这篇关于如何根据条件组得到列的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 07:56