Amazon Athena- 查询以字符串形式存储的数字的列

Raj*_*ani 6 amazon-web-services amazon-athena

我有一个保险数据集,其中包括每个县的注册人数。但是,注册数量存储为字符串。我如何查询诸如“查找注册人数超过 50 的计划”之类的数据。不幸的是 50 在数据集中存储为一个字符串,所以我需要了解如何使用 athena 运行我的查询。有人可以帮忙吗

在此处输入图片说明

shu*_*lov 5

将字符串转换为浮点数,而不是整数,并在转换之前删除逗号。这是一个例子:

with x AS 
    (SELECT '1,800,850.20' AS "value")
SELECT cast(replace(value,',', '') AS REAL)
FROM x
Run Code Online (Sandbox Code Playgroud)

因此,您应该使用:

with x AS 
    (SELECT '1,800,850.20' AS "value")
SELECT cast(replace(value,',', '') AS REAL)
FROM x
Run Code Online (Sandbox Code Playgroud)

  • @RajParpani,您在 where 子句中使用了 `total_subscribed_charge_amount`,但它没有被类型转换为 REAL。您可以使用“with”语句来修复它:“with datamart as (SELECT npi, ..., CAST(REPLACE(total_subscribed_charge_amount, ',', '') AS REAL) as Total_subscribed_charge_amount FROM cmsaggregate payment2017) select * from datamart WHERE Total_subscribed_charge_amount >“100000”和provider_zipcode=“90250”按total_subscribed_charge_amount ASC LIMIT 1000排序` (3认同)