SQL error code in Athena Your query has the following error(s): SYNTAX_ERROR: line 5:8: Column 'amount' cannot be resolved

SQL error code in Athena Your query has the following error(s): SYNTAX_ERROR: line 5:8: Column 'amount' cannot be resolved

在 AWS Athena 中,我有如下 SQL 查询:

select licence, count(distinct (id)) as amount
from "database_name" 
where YEAR(column_year) = 2021
group by licence
having amount > 10
order by amount desc

*然后我得到错误:

SYNTAX_ERROR: line 5:8: Column 'amount' cannot be resolved. This query ran against the "database_name", unless qualified by the query.*

我做错了什么?

2 件事。

  1. Having子句中不能使用别名,必须使用精确列计算
  2. Distinct 不是一个函数,所以你可以在没有括号的情况下使用它。
select licence, count(distinct id) as amount
from "database_name" 
where YEAR(column_year) = 2021
group by licence
having count(distinct id) > 10
order by amount desc