hive Expression Not In Group By Key

前端 未结 3 2120
后悔当初
后悔当初 2020-12-09 18:37

I create a table in HIVE. It has the following columns:

id bigint, rank bigint, date string

I want to get avg(rank) per month. I can use th

相关标签:
3条回答
  • 2020-12-09 19:04

    This is because there is more than one ‘date_saved’ record under your group by. You can turn these ‘date_saved’ records into arrays and output them.

    0 讨论(0)
  • 2020-12-09 19:09

    A walk around is to put the additional field in a collect_set and return the first element of the set. For example

    select a.lens_id, avg(a.rank), collect_set(a.date_saved)[0]
    from lensrank_archive a
    group by a.lens_id, year(a.date_saved), month(a.date_saved);
    
    0 讨论(0)
  • 2020-12-09 19:17

    The full error message should be in the format Expression Not In Group By Key [value].
    The [value] will tell you what expression needs to be in the Group By.

    Just looking at the two queries, I'd say that you need to add a.date_saved explicitly to the Group By.

    0 讨论(0)
提交回复
热议问题