Hive QL解题流程详解四

本文详细解析了两道Hive SQL题目:一是根据线上服务器访问日志创建表并实现特定查询;二是针对账号表进行分组查询,找出每个区组中money排名前十的账号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第7题

有一个线上服务器访问日志格式如下(用sql答题)

时间 接口 ip地址

2016-11-09 11:22:05 /api/user/login 110.23.5.33

2016-11-09 11:23:10 /api/user/detail 57.3.2.16

.....

2016-11-09 23:59:40 /api/user/login 200.6.5.166

数据集

2016-11-09 14:22:05	/api/user/login	110.23.5.33
2016-11-09 11:23:10	/api/user/detail	57.3.2.16
2016-11-09 14:59:40	/api/user/login	200.6.5.166
2016-11-09 14:22:05	/api/user/login	110.23.5.34
2016-11-09 14:22:05	/api/user/login	110.23.5.34
2016-11-09 14:22:05	/api/user/login	110.23.5.34
2016-11-09 11:23:10	/api/user/detail	57.3.2.16
2016-11-09 23:59:40	/api/user/login	200.6.5.166
2016-11-09 14:22:05	/api/user/login	110.23.5.34
2016-11-09 11:23:10	/api/user/detail	57.3.2.16
2016-11-09 23:59:40	/api/user/login	200.6.5.166
2016-11-09 14:22:05	/api/user/login	110.23.5.35
2016-11-09 14:23:10	/api/user/detail	57.3.2.16
2016-11-09 23:59:40	/api/user/login	200.6.5.166
2016-11-09 14:59:40	/api/user/login	200.6.5.166
2016-11-09 14:59:40	/api/user/login	200.6.5.166

需求:

求11月9号下午14点(14-15点),访问api/user/login接口的top10的ip地址

1)建表

create table address(
time string,
interface string,
ip string
)
row format delimiter
fields terminated by '\t';

2)需求SQL

select
ip,
interface,
count(*) ct
from
address
where
date_format(time,'yyyy-MM-dd HH')>='2016-11-09 14'
and
date_format(time,'yyyy-MM-dd HH')<='2016-11-09 15'
and
interface='/api/user/login'
group by
ip,interface
order by
ct desc
limit 10;

第8题

有一个账号表如下,请写出SQL语句,查询各自 区组的money排名前十的账号(分组取前10)

1) 建表

create table `account`(
dist_id int(11) default null comment '区组id',
`account` varchar(100) default comment '账号',
`gold` int(11) default 0 comment '金币'
);

需求:查询各自 区组的money排名前十的账号(分组取前10)

select
*
from
account as a
where
(select
count(distinct (a1.gold))
from
account as a1
where
a1.dist_id = a.dist_id
and 
a1.gold>a.gold) <3;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值