任务描述

本关任务:分析2018年点击量最高的10个网站域名。

编程要求

在右侧编辑器补充代码,分析出2018年点击量最高的10个网站域名。

创建数据库:mydb

创建原始表:db_search

字段名 类型 注释
id string 用户编号
key string 搜索关键词
ranking int URL在返回结果中的排名
or_der int 点击顺序
url string 域名
time string 时间

部分数据如下:

数据切分方式:空格

数据所在位置:/root/data.txt

测试说明

平台会对你编写的代码进行测试:

预期输出:

  1. bbs.union.daqi.com 1822
  2. www.qihoo.com 1714
  3. ent.sina.com.cn 937
  4. bbs.phoenixtv.com 857
  5. yule.sohu.com 827
  6. club.chinaren.com 827
  7. click.cpc.sogou.com 807
  8. blog.sohu.com 737
  9. news.sina.com.cn 649
  10. 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 ----------
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐