regex - 如何从字符串中提取前两位数字?
问题描述
我有下面的查询,它只返回我的字符串字段的数值,我想将它限制为两个输出字符。
询问
SELECT NULLIF(regexp_replace(temperature, '\D','','g'), '')::numeric AS "Temperature"
from tbl_temperature_hosts
where temperature like '%Core 0%' limit 1
输出
6601205698
预期结果
66
解决方案
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
推荐阅读
- asp.net - ASP.Net Razor 页面生成错误的 URL
- java - 如何让 stdlib.jar 在 Intellij 中工作?
- perl - perl 和 sed 中的相同正则表达式的工作方式不同
- android - 如何为小于O的android创建通知通道
- prolog - 我们如何在prolog中做一个循环?
- html - Asp.net Core 根据模型值在特定位置动态插入 HTML 元素
- node.js - 静态服务 nuxt 应用程序时代理模块不起作用
- node.js - Promise 和 Async 函数的问题
- c++ - 如何打印输入值
- android - CalendarPickerView 无法在 Firebase 内部初始化获取调用