复现
select deptno `dept`,
year(hiredate) `year`,
sum(sal)
from tb_emp
group by deptno,year;
org.apache.hadoop.hive.ql.parse.SemanticException:Line 5:16 Invalid
table alias or column reference ‘year’: (possible column names are:
empno, ename, job, mgr, hiredate, sal, comm, deptno)
原因
在hive中,group by的执行顺序在select之前
ps:hive中别名的使用都是严格遵循sql执行顺序的,groupby后面不能用别名
spark-sql 实操可以