pgsql将字符串转为浮点数
作者:互联网
如 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
标签:monitor,浮点数,float,value,pgsql,字符串,avg,data,final 来源: https://www.cnblogs.com/qianqiantongxie/p/15945173.html