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'
1条答案
按热度按时间kq4fsx7k1#
试试下面,
查询要求聚合函数是select子句的一部分。
下面的查询工作-我们只能在having子句中使用聚合函数,但它只能是count(*)
但下面的查询抛出错误-
希望这有帮助