Hive 报错 Invalid column reference 列名

两张表

Hive 报错 Invalid column reference 列名_第1张图片

Hive 报错 Invalid column reference 列名_第2张图片

 

当我执行

select m.movieid,m.moviename,substr(m.moviename,-5,4) as years,avg(r.rate) as avgScore
FROM t_movie as m join t_rating as r on m.movieid = r.movieid 
GROUP by m.movieid
HAVING avgScore >= 4;

报错:

Invalid column reference 'moviename'

 

改成下,就好了

select m.movieid,m.moviename,substr(m.moviename,-5,4) as years,avg(r.rate) as avgScore
FROM t_movie as m join t_rating as r on m.movieid = r.movieid 
GROUP by m.movieid,m.moviename
HAVING avgScore >= 4;

 

我理解为,t_movie 表的 userid 与 moviename 两字段都是唯一的,所以分组的时候要一起写

 

 

 

 

 

 

你可能感兴趣的:(hive)