划分存储在varchar中的数字

时间:2016-12-14 19:13:49

标签: sql postgresql types

我需要专家协助如何在Postgres中划分varchar

我有两列,“Price”和“Sq_Ft”。价格附有美元符号并包含逗号,而Sq_Ft仅包含逗号。

"Price"             "Sq_Ft"                    
$352,900             3,478
$357,630             3,587
$445,360             1,589

解决此问题并分割两个varchar值的最可行方法是什么?

1 个答案:

答案 0 :(得分:3)

select  "Price"::money / to_number("Sq_Ft",'99999999999')
from    t
;
+---------+
| $101.47 |
+---------+
| $99.70  |
+---------+
| $280.28 |
+---------+

select  to_number("Price",'99999999999') / to_number("Sq_Ft",'99999999999')
from    t
;
+----------------------+
| 101.4663599769982749 |
+----------------------+
| 99.7017005854474491  |
+----------------------+
| 280.2769037130270610 |
+----------------------+