Hivesql:invalid column 参考'2'

eiee3dmh  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(377)

我的配置单元sql:

select id from Table
where date>'20180101'
and date<'20190101'
group by id
having count(distinct substr(date,5,2))=7

并返回一个error:invalid column 参考'2'
为什么以及如何修复?

kq4fsx7k

kq4fsx7k1#

试试下面,
查询要求聚合函数是select子句的一部分。

with table1 as (select 1 as id, '20180101' as date1 union select 1 as id, '20110101' as date1 union select 1 as id, '20190101' as date1 union select 2 as id, '20180101' as date1 union select 3 as id, '20180102' date1) select id, count(distinct substr(date1,5,2)) from table1 where date1>'20180101' and date1<'20190101' group by id having count(distinct substr(date1,5,2))=7;

下面的查询工作-我们只能在having子句中使用聚合函数,但它只能是count(*)

select id from table1 where date1>'20180101' and date1<'20190101' group by id having count(date1)=7;

但下面的查询抛出错误-

select id from table1 where date1>'20180101' and date1<'20190101' group by id having count(distinct (date1))=7;
FAILED: SemanticException [Error 10002]: Line 1:319 Invalid column reference 'date1'

希望这有帮助

相关问题