Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query error: Failed to recognize predicate 'group'. Failed rule: 'identifier' in subquery source

Tags:

sql

hive

I tried the below query in hive. I get the error "Failed to recognize predicate 'group'. Failed rule: 'identifier' in subquery source".

From my understanding, I am not sure on what does that error mean in the below query. Any suggestions would be great !!

select val1, val2, count(distinct(val3)) from (
    select val1, val2, val3
    from tab1
    where (val1 in ('A', 'B') 
    or val2 in ('C', 'D')))
group by val1, val2
like image 854
user3447653 Avatar asked Jun 01 '17 15:06

user3447653


1 Answers

You have to alias your sub-query:

select val1, val2, count(distinct(val3)) from (
    select val1, val2, val3
    from tab1
    where (val1 in ('A', 'B') 
    or val2 in ('C', 'D'))) as t
group by val1, val2
like image 111
Yuck Avatar answered Oct 04 '22 21:10

Yuck