Search code examples
sqlselectgroup-byimpalahaving-clause

cannot use having in impala


where I use "having" in impala sql,I got an error "Could not resolve column/field reference"

select count(dst_ip) as times, dst_ip 
from test_mode 
group by dst_ip 
having times > 1

I don't konw why, impala document is support having https://impala.apache.org/docs/build/html/topics/impala_group_by.html#group_by

error


Solution

  • Few databases support reusing aliases defined in the select in the having clause (MySQL comes to mind). I don't think that this belongs to standard ANSI SQL .

    In most other databses, such as Impala, you need to repeat the expression:

    select count(dst_ip) as times, dst_ip 
    from test_mode 
    group by dst_ip 
    having count(dst_ip) > 1