简体   繁体   English

查询以仅从单元格中获取数字 - 雪花

[英]Query to get only numbers from a cell - Snowflake

I have a huge column in Snowflake named "AGE" and 5% of the rows have values like ">80".我在 Snowflake 中有一个名为“AGE”的巨大列,其中 5% 的行具有“>80”之类的值。

I want to filter by people with AGE between [40 55] and I am facing an error "Numeric value '>80' is not recognized".我想按年龄在 [40 55] 之间的人进行过滤,但我遇到了错误“无法识别数值 '>80'”。

I was trying to filter using something like "where ISNUMERIC(PAT_AGE_YR_NBR)=1" but ISNUMERIC is not recognized in Snowflake.我试图使用类似“where ISNUMERIC(PAT_AGE_YR_NBR)=1”的内容进行过滤,但在 Snowflake 中无法识别 ISNUMERIC。 I want to either:我想要:

  • select the rows that are only numerical or select 只有数字的行或
  • retrieve the value out of them, like in the case ">80", I want to filter by only the numerical part of the cell, "80".从中检索值,例如在“>80”的情况下,我只想按单元格的数字部分“80”进行过滤。

Any ideas?有任何想法吗? cheers干杯

  1. For the first part you can use TRY_TO_NUMERIC function as detailed in the mentioned documentation.对于第一部分,您可以使用TRY_TO_NUMERIC function,如上述文档中所述。
  1. And then from the result you may then do a filter for the values where NULL is coming and have only the specific results listed.然后从结果中,您可以对 NULL 即将到来的值进行过滤,并仅列出特定结果。

For eg:例如:

select try_to_numeric(col) as a from numtest where a IS NOT NULL and a > 10;

Use a TRY_ function:使用TRY_

WHERE TRY_CAST(PAT_AGE_YR_NBR AS INT) between 40 and 55

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM