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

 

pgsql将字符串转为浮点数

 

 

pgsql将字符串转为浮点数

 

上一篇:Angular基础篇 —— Rxjs之二:distinct, distinctUtilChanged, filter


下一篇:linux安装python