group by在mysql和hive中的区别

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前先执行,所以此时别名在解析器中没法识别。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值