id name date sex
1 赵雷 1990-01-01 男
2 钱电 1990-12-21 男
3 孙风 1990-05-20 男
4 李云 1990-08-06 男
5 周梅 1991-12-01 女
6 吴兰 1992-03-01 女
7 郑竹 1989-07-01 女
8 王菊 1990-01-20 女
书写顺序
select from (join on) where group by having order by limit;
执行顺序
from ( on join )where group by having select order by limit;
问题1.得出在相同一年出生的人口数
在mysql中和或hive中
select count(*),year(date) from student group by year(date);
都可以得出结果:
1 1989
5 1990
1 1991
1 1992
但是如果要在year(date)起别名
在Mysql中
select count(*),year(date) a from student group by a ;
顺利执行
但在hive中
select count(*),year(date) a from student group by a ;
Invalid table alias or column reference ‘a’: (possible column names are: s_id, s_name, s_birth, s_sex
出现报错
原因分析:
select执行顺序中,group by 在select前先执行,所以此时别名在解析器中没法识别。