Athena - 案例陈述计数

问题描述 投票:0回答:2

尝试在 AWS Athena 中执行以下操作。对我来说这似乎是标准 SQL:

select
  count(case when gender='Male' then 1 end) as male_count
  count(case when gender='Female' then 1 end) as female_count,
  count(case when gender is null then 1 end) as other_count,
  count(*) as total_count
from onepercentsampleflattened_90days_parquet;

我收到以下错误:

 line 3:3: mismatched input 'count' expecting {<eof>, ',', 'from', 'where', 'group', 'order', 'having', 'limit', 'union', 'except', 'intersect'} (service: amazonathena; status code: 400; error code: invalidrequestexception; request id: d7ccbaef-e5da-4fca-8ae8-60fb8b93ce6c)

如有任何帮助,我们将不胜感激。谢谢!

sql amazon-web-services presto amazon-athena
2个回答
5
投票

您应该在第一个计数后添加逗号,同样使用 count 会给您所有记录相同的计数,您应该使用 sum


0
投票

选择male_count、female_count、other_count, male_count+female_count+other_count 作为 ttl_count 从 ( 选择 sum(当性别='男性'时则1结束)作为male_count, sum(当性别='女性'时则1结束)作为female_count, sum(当性别为空时为 1 结束的情况) as other_count 来自 onepercentsampleflattened_90days_parquet );

© www.soinside.com 2019 - 2024. All rights reserved.