尽管使用 Amazon Athena 在书面查询中进行了强制转换,但仍无法使用逻辑运算符

Unable to use the logical operator despite of casting in the written query using Amazon Athena

我无法在其中一个列上使用逻辑运算符,即使我将其转换为大整数。"total_submitted_charge amount" 在我的数据库中存储为字符串。以下是我的查询:

SELECT npi,
         provider_last_name,
         provider_first_name,
         provider_mid_initial,
         provider_address_1,
         provider_address_2,
         provider_city,
         provider_zipcode,
         provider_state_code,
         provider_country_code,
         provider_type,
         number_of_services,
         try_cast(CAST(REPLACE(total_submitted_charge_amount,
         ',') AS DECIMAL) AS BIGINT) AS total_submitted_amount
FROM cmsaggregatepayment2017
WHERE provider_zipcode='90250'

我一添加 " AND total_submitted_amount>2000",查询就停止工作。有人可以指导我吗

根据 SQL 规范,total_submitted_amount 是一个投影,只能在 "outer" 范围内使用。 IE。你可以

SELECT * FROM ( <your query> ) WHERE total_submitted_amount > 2000

< your query >
...  AND try_cast(CAST(REPLACE(total_submitted_charge_amount, ',') AS DECIMAL) AS BIGINT) > 2000

注意:第二次使用表达式没有性能损失,它仍然会在 Presto 中每行计算一次(Athena 基于 Presto)。