hive的排序,分組练习
hive的排序,分組练习
数据:
添加表和插入数据(数据在Linux本地中)
create table if not exists tab1(
IP string,
SOURCE string,
TYPE string
)
row format delimited fields terminated by '|'
stored as textfile;
load data local inpath '/home/data/data1.txt' into table tab1;
1.问题:(top10)按照来源排序,访问量高的排最上面
select source,count(*) num
from tab1
group by source
order by num desc;
select 查询在order by 前
2.问题:(推荐系统)给一个用户ip地址,得到用户经常访问的应用类型后,推荐用户同种类型的其他应用
数据二:
建表,填数据:
create table if not exists tab2(
id string,
name string,
url string,
pid string
)
row format delimited fields terminated by '\t'
stored as textfile;
load data local inpath '/home/data/data2.txt' into table tab2;
1.问题:(数据清洗)合并name与url,格式为 NAME:name|URL:url
select concat('NAME:',name,'|','URL:',url)
from tab2
where name is not null and url is not null;
数据三:
表的建立和数据插入
create table if not exists tab4(
no string,
province string,
city string,
pid string,
cid string
)
row format delimited fields terminated by '\t'
stored as textfile;
load data local inpath '/home/data/data4.txt' into table tab4;
1.问题:从源数据中筛出pid与省份、cid与城市,并且创建新表保存 去重 distinct
这里使用加行键的方法,实行唯一标识。
select pid,province
from tab4
group by pid,province
limit 1
select t1.cid,t1.city,t1.rank
from(
select cid,city,row_number() over (partition by cid order city) rank
from tab4
group by cid,city) t1
where t1.rank=1;
数据四:
新建表以及添加数据
create table if not exists tab5(
lac string,
cellid string,
cell_name string,
longitude string,
latitude string
)
row format delimited fields terminated by '\t'
stored as textfile;
load data local inpath '/home/data/data5.txt' into table tab5;
1.问题:从cell_name列中截取需要的部分,例如 HZD0090,截取D0090杭州四季青蔬菜公司,截取D0090
数据五:
建表+添加数据
create table if not exists tab6(
id string,
service string
)
row format delimited fields terminated by '\t'
stored as textfile;
load data local inpath '/home/data/data6.txt' into table tab6;
问题:去除所有父类服务,只要子类服务(id 是字符串类型)
select * from tab6 where id>100
数据六:
添加数据:
create table if not exists tab7(
id string,
type string,
sagem string
)
row format delimited fields terminated by '\t'
stored as textfile;
load data local inpath '/home/data/data7.txt' into table tab7;
问题:按照设备类型,统计出现的频率
select type,count(*)
from tab7
group by type;
数据七:
问题:去重后存入到新表中
select col,row_number() over (partition by col order by col) rank
from tab10
group by col;
hive的排序,分組练习的更多相关文章
- Hive为什么要分桶
对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...
- Hive学习笔记——Hive中的分桶
对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...
- Hive 学习之路(五)—— Hive 分区表和分桶表
一.分区表 1.1 概念 Hive中的表对应为HDFS上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为HDFS上表目录的子目录,数据按照分区存储在子目录中.如 ...
- Hive 系列(五)—— Hive 分区表和分桶表
一.分区表 1.1 概念 Hive 中的表对应为 HDFS 上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为 HDFS 上表目录的子目录,数据按照分区存储在子 ...
- 入门大数据---Hive分区表和分桶表
一.分区表 1.1 概念 Hive 中的表对应为 HDFS 上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为 HDFS 上表目录的子目录,数据按照分区存储在子 ...
- Crystal Report分組中的序號重新遞增
客戶要批次列印發票,也就是報表需要按照發票號碼(INV_NO)進行分組,每個發票里還有明細的item,之前因為直接抓RecordNumber,所以該欄位只能從1開始計數,遇到新的發票發號不會重新從1開 ...
- hive 分组排序,topN
hive 分组排序,topN 语法格式:row_number() OVER (partition by COL1 order by COL2 desc ) rankpartition by:类似hiv ...
- hive -- 分区,分桶(创建,修改,删除)
hive -- 分区,分桶(创建,修改,删除) 分区: 静态创建分区: 1. 数据: john doe 10000.0 mary smith 8000.0 todd jones 7000.0 boss ...
- laravel 路由分組
laravel 路由分組 Route::group(['prefix' => 'admin'], function () { $namespacePrefix="\\App\\Http ...
随机推荐
- css基础面试题
1 介绍一下标准的CSS的盒子模型?与低版本IE的盒子模型有什么不同的? 标准盒子模型:宽度=内容的宽度(content)+ border + padding + margin低版本IE盒子模型:宽度 ...
- python 名称前的单下划线
单前导下划线 _var 1.特点一 在PEP8约定中定义,以单个下划线开头的变量或方法仅供内部使用.用于指定该名称属性为“私有”.为了使其他人(或你自己)使用这些代码时将会知道以“_”开头的名称只供内 ...
- nodejs笔记之事件循环
Event Loop (事件循环或者事件轮询) Event Loop是一个程序结构,用于等待和发送消息和事件. 简单说,就是在程序中设置两个线程:一个负责程序本身的运行,称为"主线程&q ...
- 移动端与pc端如何用localStorage实现历史纪录?
1.使用jq完成localStorage实现历史纪录版. 代码如下: <!DOCTYPE html> <html> <head lang="en"&g ...
- Dio添加Cookie
在使用Options添加headers时,Map没有定义内部类型: Dio dio = new Dio(); Map headers = new Map(); headers['Cookie'] = ...
- 2.裴波那契(Fibonacci)数列
裴波那契(Fibonacci)数列 f(n)= ⎧⎩⎨0,1,f(n−1)+f(n−2),n =0n =1n>1 求裴波那契数列的第n项.(题目来自剑指offer) 1.递归解法,效率很低的解法 ...
- kubernetes版本融合解决方案
kubernetes版本融合背景 在kubernetes 1.6版本的基础上进行了深度的定制.而且该版本已经相当稳定.但是随着kubernetes版本迭代,后期使用的如service mesh/kub ...
- centos7 安装pgsql
1.添加prm安装源(或者从官网下载) PostgreSQL官网地址:https://yum.postgresql.org/ yum install https://download.postgres ...
- 快速签发 Let's Encrypt 证书指南
本文仅记录给自己的网站添加"小绿锁"的动手操作过程,不涉及 HTTPS 工作原理等内容的讲解,感兴趣的同学可以参考篇尾的文章自行了解. 简单了解下我的实验环境: 云服务器:Cent ...
- 防cc攻击策略
黑客攻击你的网站,会采取各种各样的手段,其中为了降低你网站的访问速度,甚至让你的服务器瘫痪,它会不断的刷新你的网站,或者模拟很多用户同一时间大量的访问你的网站, 这就是所谓的CC攻击,这就需要我们在程 ...