首页 > 解决方案 > 如何从字符串中提取前两位数字?

问题描述

我有下面的查询,它只返回我的字符串字段的数值,我想将它限制为两个输出字符。

询问

SELECT NULLIF(regexp_replace(temperature, '\D','','g'), '')::numeric AS "Temperature"
from tbl_temperature_hosts
where temperature like '%Core 0%' limit 1

输出

6601205698

预期结果

66

标签: regexdatabasepostgresql

解决方案


SELECT substring(NULLIF(regexp_replace(temperature, '\D','','g'), '')::numeric::text from 1 for 2)::numeric AS "Temperature"
from tbl_temperature_hosts
where temperature like '%Core 0%' limit 1

推荐阅读