SQL查询每月的平均值
SQL查询每月价格的平均值:
有这么一个Table表:
addtime jiage
2011-01-01 01:05:00 100
2011-02-01 01:25:00 112
2012-01-01 01:55:00 11
2012-01-11 01:55:00 38
2012-01-19 01:55:00 38
2013-11-01 02:05:00 14
2014-01-02 02:25:00 17
20014-01-02 02:55:00 18
要求,按日期查出每月的平均值
如:
2011-1 100
2011-2 112
2012-1 (11+38+38)/3
2013-11 14
…
这样显示出所有的数据,谢谢各位大神了哈~
------解决方案--------------------select convert(varchar(7),addtime, 23 )
,avg(jiage) from d group by convert(varchar(7) ,addtime, 23 )
------解决方案--------------------select
convert(varchar(7),addtime,23) [datetime]
,avg(jiage) avg_jiage
from d
group by
convert(varchar(7),addtime,23)
order by [datetime]