1,nv,18,吃棒棒糖
2,gong,18,养金鱼
3,nv,20,做头发
4,ry,18,自high
5,gong,18,养乌龟
6,gong,19,养鸭子
7,gong,38,养鸡鸡
8,nv,22,做头发
9,nv,23,买衣服
10,ry,28,下围棋
11,ry,18,跳舞
create table userinfo(
id int,
sex string,
age int,
hobby string
)
row format delimited fields terminated by ',';
load data local inpath '/uardata/hivetest/userinfo' into table userinfo;
select id, sex, age, hobby ,row_number() over(partition by sex order by age desc) as od from userinfo ;
首先将数据存入临时表
create table userinfo_tmp as select id, sex, age, hobby ,row_number() over(partition by sex order by age desc) as od from userinfo ;
然后通过od查询最大两人
hive> select * from userinfo_tmp where od < 3;
OK
7 gong 38 养鸡鸡 1
6 gong 19 养鸭子 2
9 nv 23 买衣服 1
8 nv 22 做头发 2
10 ry 28 下围棋 1
4 ry 18 自high 2
Time taken: 0.198 seconds, Fetched: 6 row(s)
hive>