执行存储过程时,我的平均值相同。
我正在传递不同的TeamID但获得相同的平均值
存储过程:
GO
/****** Object: StoredProcedure [dbo].[uspGetVote] Script Date: 9/3/2015 12:40:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[uspGetVote](@TeamID INT)
AS
BEGIN
select avg(VoteValue) as [AverageVoteValue] from Vote where datediff(day,getdate(),LastModifiedDateTime) <= 7 Group By TeamID order by AverageVoteValue
END
请给我一个正确的查询。
谢谢
答案 0 :(得分:0)
我想你要找的是:
GO
/****** Object: StoredProcedure [dbo].[uspGetVote] Script Date: 9/3/2015 12:40:42 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[uspGetVote](@TeamID INT)
AS
BEGIN
SELECT AVG(VoteValue) AS [AverageVoteValue] FROM Vote
WHERE DATEDIFF(day,getdate(),LastModifiedDateTime) <= 7
AND TeamId = @TeamID
GROUP BY TeamId
ORDER BY AverageVoteValue
END