本文部分参考自:https://blog.csdn.net/qq_23897391/article/details/100688796
Hive第七天——Hive函数
自己的话:千里之行,始于足下。
每天都要保持前进,我势必要有强劲的实力,再跟明天的自己问好。
开窗函数:组内排序
开窗函数的固定写法:
over(partition by 列名1,列名2 …… order by 列名3,列名4 …… [desc])
数据准备:
新建test.txt文件,输入如下的三列数据,以空格分隔。第一列是月份,第二列代表商铺名称,第三列代表该商铺该月营业额(万元)。
[root@hadoop ~]# vim test.txt
2019-01 a 4
2019-01 b 3
2019-01 c 3
2019-01 d 2
2019-01 e 1
2019-02 a 1
2019-02 b 2
2019-02 c 3
2019-02 d 3
2019-02 e 4
在hive中新建表temp_test10,将test文件中的数据插入,查看数据。
hive >CREATE TABLE temp_test10 (
>month STRING comment '月份',
>shop STRING comment '商铺名称',
>money STRING comment '营业额(万元)')
>row format delimited
>fields terminated BY ' ';
hive >load data local inpath '/root/test.txt' into table temp_test10;
hive >select * from temp_test10;
temp_test10.month temp_test10.shop temp_test10.money
2019-01 a 4
2019-01 b 3
2019-01 c 3
2019-01 d 2
2019-01 e 1
2019-02 a 1
2019-02 b 2
2019-02 c 3
2019-02</