IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> Hive的进阶操作 -> 正文阅读

[大数据]Hive的进阶操作

1.前置准备

数据准备

18999001	王述龙	男	1998-12-10	上海	98	100	2000
18999002	孙宇鹏	男	1999-11-17	沈阳	51	500	
18999003	王应龙	男	2000-02-04	沈阳	59	100	
18999004	张琼宇	女	1999-07-01	大连	89	200	
18999005	宋传涵	女	1999-07-20	上海	86	100	1000
18999006	李亚楠	女	1998-01-24	杭州	97	200	2000
18999007	侯楠楠	男	2000-01-29	北京	79	200	
18999008	陈姝元	女	1999-06-24	北京	96	200	1500
18999009	陆春宇	男	1998-01-18	沈阳	87	300	1000
18999010	孙云琳	女	1997-07-15	上海	56	300	
18999011	尤骞梓	女	1999-04-25	杭州	86	200	1000
18999012	张爱林	男	1999-05-16	北京	92	400	1500
18999013	曹雪东	男	2000-11-20	北京	78	300	
18999014	贾芸梅	女	2000-06-12	大连	88	400	1000
18999015	温勇元	男	1999-08-08	上海	65	500	
18999016	张微微	女	1998-01-27	北京	90	400	1500
18999017	李君年	男	1998-03-21	上海	78	500	
18999018	卢昱泽	女	1998-08-01	上海	57	500	
18999019	赵旭辉	男	1999-02-18	北京	75	500	
18999020	张矗年	男	1997-07-26	重庆	86	300	1000

在这里插入图片描述

2.流程实操

创建一个数据仓库hrsystem,并切换到该库中。

create database hrsystem;

use hrsystem;

show databases;

在hrsystem数据仓库中创建一张外部表:学生表emp。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-80tUqsgH-1654087092827)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220601202340058.png)]

在这里插入图片描述

create external table if not exists emp(
    sno int comment"学号",
    sname string comment"姓名",
    gender string comment"性别",
    bday string comment"出生日期",
    area string comment"地区",
    score double comment"成绩",
    deptno string comment"所在学院",
    scholarship double comment"奖学金"
)row format delimited fields terminated by '\t';

在这里插入图片描述

将外部表转换为内部表。

alter table emp set tblproperties('EXTERNAL'='FLASE');

查询表结构的详细信息。

desc formatted emp;

在这里插入图片描述

将本地文件/opt/datas/emp.txt导入到学生表emp中。

load data local inpath '/opt/datas/emp.txt' into table emp;

在浏览器中查看HDFS上学生表emp的数据。

在这里插入图片描述

查询奖学金scholarship不为空的所有学生信息。

select * from emp where scholarship is not null;

在这里插入图片描述

查询学生表emp中平均成绩小于70分的学号。

Having和Where的区别
where作用于表中的列,having作用于查询结果中的列
where后不能写分组函数,having后可以使用分组函数

select sno, avg(score) avg_score 
from emp group by sno
having avg_score < 70;

在这里插入图片描述

查询学生表emp中平均成绩小于70分的部门。

select deptno, avg(score) avg_score
from emp group by deptno
having avg_score < 70;

在这里插入图片描述

查询出生日期中含有5的学生的姓名和生日。

select sname,bday
from emp where bday RLIKE '[5]';

在这里插入图片描述

查询学生表emp的信息,并按部门降序排列。

-- 内部排序
select * from emp sort by deptno desc;

select * from emp order by deptno desc;

在这里插入图片描述

按照学生成绩的2倍排序。

select sname, score*2 twoscore 
from emp order by twoscore;

在这里插入图片描述

查询emp表中每个部门的平均成绩。

select deptno, avg(score) avg_score 
from emp group by deptno;

在这里插入图片描述

查询成绩大于95分,或者系别是100的学生信息。

select *
from emp where score>95 or deptno=100;

在这里插入图片描述

随机抽样学生表emp中的10行记录,其中包括学生姓名sname和成绩score。

select sname,score 
from emp tablesample(10 rows);

在这里插入图片描述

利用条件函数,查询学生表emp中不同部门男女人数。

select  deptno,
  sum(case gender when '男' then 1 else 0 end) male_count,
  sum(case gender when '女' then 1 else 0 end) female_count
from emp
group by deptno;

在这里插入图片描述

了解更多知识请戳下:

@Author:懒羊羊

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2022-06-14 22:40:05  更:2022-06-14 22:40:39 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/19 21:23:00-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码