网站首页 > 技术文章 正文
好程序员大数据学习路线hive内部函数,持续为大家更新了大数据学习路线,希望对正在学习大数据的小伙伴有所帮助。
1、取随机数函数:rand()
语法: rand(),rand(int seed) 返回值: double 说明: 返回一个0到1范围内的随机数。如果指定seed,则会得到一个稳定的随机数序列
select rand();
select rand(10);
2、分割字符串函数:split(str,splitor)
语法: split(string str, string pat) 返回值: array 说明: 按照pat字符串分割str,会返回分割后的字符串数组,注意特殊分割符的转义
select split(5.0,"\.")[0];
select split(rand(10)*100,"\.")[0];
3、字符串截取函数:substr,substring
语法: substr(string A, int start),substring(string A, int start) 返回值: string 说明:返回字符串A从start位置到结尾的字符串
语法: substr(string A, int start, int len),substring(string A, int start, int len) 返回值: string 说明:返回字符串A从start位置开始,长度为len的字符串
select substr(rand()*100,0,2);
select substring(rand()*100,0,2);
4、If函数:if
语法: if(boolean testCondition, T valueTrue, T valueFalseOrNull) 返回值: T 说明: 当条件testCondition为TRUE时,返回valueTrue;否则返回valueFalseOrNull
select if(100>10,"this is true","this is false");
select if(2=1,"男","女");
select if(1=1,"男",(if(1=2,"女","不知道")));
select if(3=1,"男",(if(3=2,"女","不知道")));
5、条件判断函数:CASE
第一种格式:
语法: CASE WHEN a THEN b [WHEN c THEN d]* [ELSE e] END 返回值: T 说明:如果a为TRUE,则返回b;如果c为TRUE,则返回d;否则返回e
第二种格式:
语法: CASE a WHEN b THEN c [WHEN d THEN e]* [ELSE f] END 返回值: T 说明:如果a等于b,那么返回c;如果a等于d,那么返回e;否则返回f
select
case 6
when 1 then "100"
when 2 then "200"
when 3 then "300"
when 4 then "400"
else "others"
end
;
##创建表
create table if not exists cw(
flag int
)
;
load data local inpath '/home/flag' into table cw;
##第一种格式
select
case c.flag
when 1 then "100"
when 2 then "200"
when 3 then "300"
when 4 then "400"
else "others"
end
from cw c
;
##第二种格式
select
case
when 1=c.flag then "100"
when 2=c.flag then "200"
when 3=c.flag then "300"
when 4=c.flag then "400"
else "others"
end
from cw c
;
6、正则表达式替换函数:regexp_replace
语法: regexpreplace(string A, string B, string C) 返回值: string 说明:将字符串A中的符合java正则表达式B的部分替换为C。注意,在有些情况下要使用转义字符,类似oracle中的regexpreplace函数
select regexp_replace("1.jsp",".jsp",".html");
7、类型转换函数: cast
语法: cast(expr as ) 返回值: Expected "=" to follow "type" 说明: 返回转换后的数据类型
select 1;
select cast(1 as double);
select cast("12" as int);
8、字符串连接函数:concat;带分隔符字符串连接函数:concat_ws
语法: concat(string A, string B…) 返回值: string 说明:返回输入字符串连接后的结果,支持任意个输入字符串
语法: concat_ws(string SEP, string A, string B…) 返回值: string 说明:返回输入字符串连接后的结果,SEP表示各个字符串间的分隔符
select "千峰" + 1603 + "班级";
select concat("千峰",1603,"班级");
select concat_ws("|","千峰","1603","班级");
9、排名函数:
rownumber(): 名次不并列 rank():名次并列,但空位 denserank():名次并列,但不空位
##数据
idclass score
1190
2185
3187
4160
5282
6270
7267
8288
9293
11901
31872
21853
92931
82882
52823
create table if not exists uscore(
uid int,
classid int,
score double
)
row format delimited fields terminated by '\t'
;
load data local inpath '/home/uscore' into table uscore;
select
u.uid,
u.classid,
u.score
from uscore u
group by u.classid,u.uid,u.score
limit 3
;
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn
from uscore u
;
取前三名
select
t.uid,
t.classid,
t.score
from
(
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn
from uscore u
) t
where t.rn < 4
;
查看三个排名区别
select
u.uid,
u.classid,
u.score,
row_number() over(distribute by u.classid sort by u.score desc) rn,
rank() over(distribute by u.classid sort by u.score desc) rank,
dense_rank() over(distribute by u.classid sort by u.score desc) dr
from uscore u
;
10.聚合函数:
min() max() count() count(distinct ) sum() avg()
count(1):不管正行有没有值,只要出现就累计1 count(*):正行值只要有一个不为空就给类计1 count(col):col列有值就累计1 count(distinct col):col列有值并且不相同才累计1
11.null值操作
几乎任何数和 NULL操作都返回NULL
select 1+null;
select 1/0;
select null%2;
12.等值操作
select null=null; #null
select null<=>null;#true
猜你喜欢
- 2024-11-07 Java 常见的49个错误及避免方法!翻译作业:码农网-小峰
- 2024-11-07 「开源资讯」可视化数据库管理平台DBeaver7.2.1发布
- 2024-11-07 Mybaits中Like 的使用方式以及一些注意点
- 2024-11-07 Java 14 带来了 5 项新特性,能支持 H5 文本开发了
- 2024-11-07 JDK13正式发布:Switch表达式、GC新垃圾回收算法、低延时GC、ZGC
- 2024-11-07 sql语句基础篇 sql语句基础语句
- 2024-11-07 sql注入 sql注入原理
- 2024-11-07 SQL注入攻防入门详解 sql注入攻击原理与解决方法
- 2024-11-07 一通操作!黑客赚得数十万美元,还有一辆特斯拉
- 2024-11-07 Java数据库连接JDBC基础问答50例,Java程序员和数据库管理员必备
你 发表评论:
欢迎- 617℃几个Oracle空值处理函数 oracle处理null值的函数
- 610℃Oracle分析函数之Lag和Lead()使用
- 599℃0497-如何将Kerberos的CDH6.1从Oracle JDK 1.8迁移至OpenJDK 1.8
- 595℃Oracle数据库的单、多行函数 oracle执行多个sql语句
- 591℃Oracle 12c PDB迁移(一) oracle迁移到oceanbase
- 582℃【数据统计分析】详解Oracle分组函数之CUBE
- 572℃最佳实践 | 提效 47 倍,制造业生产 Oracle 迁移替换
- 560℃Oracle有哪些常见的函数? oracle中常用的函数
- 最近发表
-
- PageHelper - 最方便的 MyBatis 分页插件
- 面试二:pagehelper是怎么实现分页的,
- MyBatis如何实现分页查询?(mybatis-plus分页查询)
- SpringBoot 各种分页查询方式详解(全网最全)
- 如何在Linux上运行exe文件,怎么用linux运行windows软件
- 快速了解hive(快速了解美国50个州)
- Python 中的 pyodbc 库(pydbclib)
- Linux搭建Weblogic集群(linux weblogic部署项目步骤)
- 「DM专栏」DMDSC共享集群之部署(一)——共享存储配置
- 故障分析 | MySQL 派生表优化(mysql pipe)
- 标签列表
-
- 前端设计模式 (75)
- 前端性能优化 (51)
- 前端模板 (66)
- 前端跨域 (52)
- 前端缓存 (63)
- 前端aes加密 (58)
- 前端脚手架 (56)
- 前端md5加密 (54)
- 前端路由 (61)
- 前端数组 (73)
- 前端js面试题 (50)
- 前端定时器 (59)
- 前端获取当前时间 (50)
- Oracle RAC (76)
- oracle恢复 (77)
- oracle 删除表 (52)
- oracle 用户名 (80)
- oracle 工具 (55)
- oracle 内存 (55)
- oracle 导出表 (62)
- oracle约束 (54)
- oracle 中文 (51)
- oracle链接 (54)
- oracle的函数 (58)
- 前端调试 (52)
本文暂时没有评论,来添加一个吧(●'◡'●)