【发布时间】:2014-02-19 07:53:57
【问题描述】:
ALTER PROCEDURE [dbo].[K_RT_GetProdutstogrid]
@purchasedby int
AS
BEGIN
SET NOCOUNT ON;
select PS.sno, PD.productname,sum(PS.quantity) as quantity,PS.modelno from K_RT_PurchaseDet PS
inner join K_RT_ProductDetails PD on PD.sno=PS.product
where purchasedby=@purchasedby and PS.quantity!=0 and attrited='false'
group by PD.productname,PS.modelno,PS.company,PS.sno
END
通过这个我得到了作为
sno product stock modelno
1 Computer 2 Dell
2 Mobile 3 Nokia7100
3 Mobile 2 Nokia7100
但实际上我想输出为
sno product stock modelno
1 Computer 2 Dell
2 Mobile 5 Nokia7100
我是这样写的,但我没有得到请帮助我....
【问题讨论】:
-
您真的希望
sno被错误地报告为 2 个诺基亚 7100s 吗?如果是这样,显示哪个sno值是否重要?如果您实际上不需要sno,那么解决方案很简单 - 请参阅下面的@Akshay 答案。
标签: sql sql-server-2008 stored-procedures aggregate-functions