4

I am using the following code and getting the error below

      select d.searchpack,d.context, d.day,d,txnid,d.config, c.sgtype from ds3resultstats d join       
     context_header c on (d.context=c.contextid) where (d.day>='2012-11-15' and d.day<='2012-11-25' and  c.sgtype='Tickler' and d.config like 
'%people%') GROUP BY d.context limit 10;
        FAILED: Error in semantic analysis: line 1:7 Expression Not In Group By Key d

I am guessing I am using the group by incorrectly

megv
  • 1,421
  • 5
  • 24
  • 36

2 Answers2

7

when you use group by, you cannot select other additional field. You can only select group key with aggregate function.

See hive group by for more information.

Related questions.

Code example:

select d.context,count(*)
from ds3resultstats
...
group by d.context

or group by multiply fields.

select d.context, d.field2, count(*)
from ds3resultstats
...
group by d.context, d.field2
Community
  • 1
  • 1
pensz
  • 1,871
  • 1
  • 13
  • 18
2

It is expecting all the columns to be added with group by. Even I am facing the same issue however I managed to get a work around to these kind of issues. you can use collect_set with the column name to get the output. For example select d.searchpack,collect_set(d.context) from sampletable group by d.searchpack;

CinCout
  • 9,486
  • 12
  • 49
  • 67