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的排序,分組练习的更多相关文章

  1. Hive为什么要分桶

    对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...

  2. Hive学习笔记——Hive中的分桶

    对于每一个表(table)或者分区, Hive可以进一步组织成桶,也就是说桶是更为细粒度的数据范围划分.Hive也是针对某一列进行桶的组织.Hive采用对列值哈希,然后除以桶的个数求余的方式决定该条记 ...

  3. Hive 学习之路(五)—— Hive 分区表和分桶表

    一.分区表 1.1 概念 Hive中的表对应为HDFS上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为HDFS上表目录的子目录,数据按照分区存储在子目录中.如 ...

  4. Hive 系列(五)—— Hive 分区表和分桶表

    一.分区表 1.1 概念 Hive 中的表对应为 HDFS 上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为 HDFS 上表目录的子目录,数据按照分区存储在子 ...

  5. 入门大数据---Hive分区表和分桶表

    一.分区表 1.1 概念 Hive 中的表对应为 HDFS 上的指定目录,在查询数据时候,默认会对全表进行扫描,这样时间和性能的消耗都非常大. 分区为 HDFS 上表目录的子目录,数据按照分区存储在子 ...

  6. Crystal Report分組中的序號重新遞增

    客戶要批次列印發票,也就是報表需要按照發票號碼(INV_NO)進行分組,每個發票里還有明細的item,之前因為直接抓RecordNumber,所以該欄位只能從1開始計數,遇到新的發票發號不會重新從1開 ...

  7. hive 分组排序,topN

    hive 分组排序,topN 语法格式:row_number() OVER (partition by COL1 order by COL2 desc ) rankpartition by:类似hiv ...

  8. hive -- 分区,分桶(创建,修改,删除)

    hive -- 分区,分桶(创建,修改,删除) 分区: 静态创建分区: 1. 数据: john doe 10000.0 mary smith 8000.0 todd jones 7000.0 boss ...

  9. laravel 路由分組

    laravel 路由分組 Route::group(['prefix' => 'admin'], function () { $namespacePrefix="\\App\\Http ...

随机推荐

  1. px和em的区别, css权重

    PX特点:px像素(Pixel).相对长度单位.像素px是相对于显示器屏幕分辨率而言的. EM特点 1. em的值并不是固定的:2. em会继承父级元素的字体大小. 优先级:!important> ...

  2. calss 类

    class Role(object): n = 123 # 类变量,像__init__中life_value,money默认参数用类变量,如果多个类的实例那就节省了内存,类变量只在类中存一份,实例中不 ...

  3. 7个优秀的国内外移动端web框架(转)

    淘宝SUI Mobile框架   (light7框架 官网:http://www.light7.cn/)官网地址:http://m.sui.taobao.org/ SUI Mobile 是一套基于 F ...

  4. IP通信基础学习第四周(下)

    选择子网掩码时,不总是使用整个八位作为屏蔽位. 在每个子网中,子网掩码是相同的. 在划分子网的情况下,判断两台主机是不是在同一子网中,需看它们的网络号与子网地址是不是相同的. 变长子网掩码VLSM,无 ...

  5. xtrabackup 2.4.3 BUG

    用XtraBackup对备份集进行apply log 的时候,卡在 xtrabackup 版本:2.4.3 InnoDB: Waited for 1535930 seconds for 128 pen ...

  6. Navicat Premium for Mac完美破解

    前因:系统升级Mojave10.14.4,没升级成功,也可能是误删了系统下的private文件夹下的东西,导致内核崩溃.    自己鼓捣了下,恢复系统不成功,去苹果售后问了下,重装系统399,保留资料 ...

  7. golang从文件按行读取并输出

    package main import ( "fmt" "os" "bufio" "io" "time&quo ...

  8. 小试wsl

    安装 管理员权限运行powershell,执行如下命令: Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Su ...

  9. 王之泰201771010131《面向对象程序设计(java)》第十四周学习总结

    第一部分:理论知识学习部分 第12章 Swing用户界面组件 12.1.Swing和MVC设计模式 a 设计模式初识b 模型—视图—控制器模式c Swing组件的模型—视图—控制器分析 12.2布局管 ...

  10. JS(JavaScript)的进一步了解5(更新中···)

    1.针对表单的 form input select textarea type=”radio/checkbox/password/button/text/submit/reset/” 表单的事件 on ...