如 final_value 字段为 varchar 字符串类型,需先转为浮点型,再求平均值
① final_value 有小数点,字符串转浮点数
select final_value :: float from monitor_data limit 2;
② final_value 为整数,才可以将字符串转整数
select final_value :: integer from monitor_data limit 2;
③ 求平均值
select avg(g.a) from
(select AVG(final_value :: float) as A from monitor_data
union all
select avg(final_value :: float) as A from monitor_data
union all
select avg(final_value :: float) as A from monitor_data
union all
select avg(final_value :: float) as A from monitor_data
union all
select avg(final_value :: float) as A from monitor_data
union all
select avg(final_value :: float) as A from monitor_data
union all
select avg(final_value :: float) as A from monitor_data ) g