任务描述
本关任务:分析2018
年点击量最高的10
个网站域名。
编程要求
在右侧编辑器补充代码,分析出2018
年点击量最高的10
个网站域名。
创建数据库:mydb
创建原始表:db_search
字段名 | 类型 | 注释 |
---|---|---|
id | string | 用户编号 |
key | string | 搜索关键词 |
ranking | int | 该URL 在返回结果中的排名 |
or_der | int | 点击顺序 |
url | string | 域名 |
time | string | 时间 |
部分数据如下:
数据切分方式:空格
数据所在位置:/root/data.txt
测试说明
平台会对你编写的代码进行测试:
预期输出:
bbs.union.daqi.com 1822
www.qihoo.com 1714
ent.sina.com.cn 937
bbs.phoenixtv.com 857
yule.sohu.com 827
club.chinaren.com 827
click.cpc.sogou.com 807
blog.sohu.com 737
news.sina.com.cn 649
club.yule.sohu.com 627
开始你的任务吧,祝你成功!
代码如下:
---------- 禁止修改 ----------
drop database if exists mydb cascade;
---------- 禁止修改 ----------
---------- begin ----------
---创建mydb数据库
create database if not exists mydb;
---使用mydb数据库
use mydb;
---创建表db_search
create table if not exists db_search(
id string comment '用户id',
key string comment '搜索关键词',
ranking int comment 'url在返回结果中的排名',
or_der int comment '点击顺序',
url string comment '网站域名',
time string comment '日期'
)
row format delimited fields terminated by ' '
lines terminated by '\n'
stored as textfile;
---导入数据:/root/data.txt
load data local inpath '/root/data.txt' into table db_search;
--查询2018年点击量最多的10个网站域名
select url,count(*) cnt
from db_search
where year(time)='2018'
group by url order by cnt desc limit 10;
---------- end ----------