1.1.12使用hive的hql实现男女各自第一名及其它
create table score_s( id int,
sex int, chinese_s int, math_s int
)
row format delimited fields terminated by ‘\t’
;
load data local inpath ‘/hivedata/score_s.txt’ overwrite into table score_s; 1、select
- from
(select id, sex,
chinese_s,
row_number() over(distribute by sex sort by chinese_s) rm from score_s) tmp
where rm=1;
;
2 、
select id,sex,chinese_s,math_s from score_s
where sex=0 and chinese_s>80 union
select id,sex,chinese_s,math_s from score_s
where sex=1 and math_s>80
;
1.1.13使用hive的hql实现最大连续访问天数
参考答案
select b4.uid,max(l3) l4 from
(
select uid,count(l2) l3 from
(
select *,date_sub(time,l1) l2 from
(
select *,
row_number() over(partition by uid order by time) l1
from
(select substr(log_time,0,10) time,uid from log_times) b1
)b2
)b3
group by uid,l2
)b4 group by b4.uid