select id, (col1+col2+ col3)/3 as avgVal from T1 where id=123
select start, end, avg(value) from (
select t2.start, t2.end, t1.value from t1 left join t2 on t1.key between t2.start and t2.end
) as x group by start,end
效果见下图:
给你举个例子,你自己按照你所在当前表的情况来进行查询。例如:select 列1 avg(列2) as xz from 表 group by 列1 order by xz desc 解释:avg()函数是求某列的平均值,group by是对某列分组,按照SQL标准,分组要和聚合函数一起配合使用才有意义[虽然在mysql中不会报错]。order by xz desc表示的是对xz进行降序,就可以把最高的平均值算出来。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)