如何根据日期来分组算出“zj”这个字段的平均值,日期是不固定的,需要从前台传递两个参数,一个开始日期,一个结束日期,如果根据传递的参数日期,在在此日期的区间进行计算。还要分组显示出来。数据库是sqlserver2008。
3 个解决方案
#1
where group avg
#2
declare @state datetime,@end datetime
set @state ='2013-03-04'
set @end ='2013-04-01'
select avg(zj)avgzj from [表名]
where [jcrq] between @state and @end group by [jcrq]
#3
MY GOD...
#1
where group avg
#2
declare @state datetime,@end datetime
set @state ='2013-03-04'
set @end ='2013-04-01'
select avg(zj)avgzj from [表名]
where [jcrq] between @state and @end group by [jcrq]
#3
MY GOD...