栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

hive关于一个表的操作

hive关于一个表的操作

1,创建表格

create table stu(name string,hobby array,scores map)
row format delimited
fields terminated by ','
collection items terminated by '-'
MAP KEYS TERMINATED BY ':';

2,导入数据
数据:

zs,drink-eat,english:90-math:66
ls,drink-playgames-chat,english:60-math:66
w6,drink,english:80-math:66
w7,playgames,english:90-math:70
z9,drink-eat,english:90.4-math:66.5
x8,drink,english:80.3-math:66.7

load 命令导入数据到表中

load data local inpath '/root/data' into table stu;

3,练习
查询所有

select * from score

关系运算符
1、查询math成绩大于66的学生

select * from score where scores['math']>66

2、查询math成绩等于66的学生

select * from score where scores['math']=66

3、查询math成绩不等于90的学生

 select * from score where scores['math']<>90;

4、like 查询类似的
w开头的数据 和s结尾的数据

select * from score where name like 'w%';
select * from score where name like '%s'

算术运算符
1、相加 语文+数学的成绩和

select scores['chinese']+scores['math']from score

数学函数
1、四舍五入

select round(scores['english']) from stu where name='z9';

2、floor 丢弃

select floor(scores['math']) from stu where name='x8';

3、ceil 进一

select ceil(scores['english']) from stu where name='x8';

4、max最大值
找到数学成绩最高是多少

select max(scores['math']) from stu;

5、sum

select sum(scores['math']) from stu;

6、avg平均

select avg(scores['math']) from stu;

7、列的方差
var_pop

select var_pop(scores['math']) from stu;

收集函数
1、size (数组 或者 map)返回集合个数
找出每个人的爱好有几个

select name,size(hobby) from stu;

字符串函数
1、length:返回长度

select name,length(name) from stu;

2、regexp_replace(string A, string B, string C)
字符串A中的B字符被C字符替代
姓名中的z被x代替:

select regexp_replace(name,'z','x') from stu;

3、trim去掉字符串两边的空格
trim(string A):去掉A两边的空格
4、split(string str, string pat):按照pat分割str返回一个数组
5、explode(array a):把一个数组打散为多行

其他
corr(col1, col2)
返回两列数值的相关系数

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/650297.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号