我想对字符串中的所有数字求和“您的3美分不等于我的600美元”。预期的输出是603。
这是我到目前为止所拥有的:
SELECT sum(s)
FROM (select regexp_split_to_table('your 3 cents is not equal to my 600
dollars','\d{1,}')) as s;
但是我收到错误“函数sum(record)不存在”。
感谢您的帮助!
我建议regexp_matches()
将字符串提取到一组数组中,然后进行转换和聚合:
select sum(val[1]::int) res
from regexp_matches('your 3 cents is not equal to my 600 dollars','\d+', 'g') x(val)
| RES | | -:| | 603 |
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句