Query does not found column, suggests same column in Hive SQL -


i have following query in sql:

select midquery.account, midquery.name, midquery.label,  midquery.labelfrequency from(      -- count appearance of each label.      select count(*) labelfrequency, account, name, label     from(          select account, name, label mytable       ) innerquery      group account, name, label ) midquery  -- select frequent values only. rank() on      (partition midquery.account, midquery.name       order midquery.labelfrequency desc) = 1      

the idea find frequent label per name-account set. when run query, following error:

error while compiling statement: failed: semanticexception [error 10002]: line 12:74 invalid column reference 'labelfrequency': (possible column names are: labelfrequency, account, name, label) 

i don't quite understand why interpreter not find column labelfrequency can suggest it. have got suggestions on how tackle issue?

edit: if move rank() select part, results.

select midquery.account, midquery.name, midquery.label,  midquery.labelfrequency,      rank() on (partition midquery.account, midquery.name       order midquery.labelfrequency desc) from(      -- count appearance of each label.      select count(*) labelfrequency, account, name, label     from(          select account, name, label mytable       ) innerquery      group account, name, label ) midquery 

window functions not allowed in where clause. there reasons this, can think of rule of sql -- similar column aliases not being recognized.

(the real reason specifying how window function operate when there multiple filtering conditions. (almost ?) impossible come coherent set of rules.)

having said that, can simplify query:

select t.account, t.name, t.label, t.labelfrequency (select count(*) labelfrequency, account, name, label,              rank() on (partition account, name                           order count(*) desc                          ) seqnum       mytable t       group account, name, label      ) t seqnum = 1; 

that is, window functions , aggregation functions can combined. , don't need subquery specify handful columns.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -