计算一条记录的平均值实际上就是横向求平均值,可以参考下例:
创新互联建站主要从事网站设计制作、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务大通,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:028-86922220
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;
效果见下图:
MySQL AVG函数
比如: SELECT AVG(student_score) AS score_avg FROM tb_students_score;