Hive报错"Expression not in GROUP BY key"

select user_id,
       distance
  from table a
 group by user_id

这是由于根据user_id做group by时,每个user_id存在多个distance,考虑只保留一个distance或使用collect_set函数。

select user_id,
       min(distance)
  from table a
 group by user_id
select user_id,
       collect_set(distance) as distances
  from table a
 group by user_id

你可能感兴趣的:(Hive)