Java教程

pgsql将字符串转为浮点数

本文主要是介绍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将字符串转为浮点数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!