sql知识点补充


1. 正则函数

  • rlike:| 表示or
rlike 'yoyo|haha'
  • regexp_replace:正则替换
regexp_replace('foobar','oo|ar','')

在这里插入图片描述

  • regexp_extract:正则拆分
    在这里插入图片描述
  • 随机函数在这里插入图片描述

2. 表相关操作

  • 建表
creat tabel facade.traing --删表:drop
(
	`年份` int
	`月份` int
)row format delimited fields terminated by ","

在这里插入图片描述

  • 临时表
with tep as(select * from table)
  • union
    union: 去重
    union all: 不去重

3. 数据格式

  • 自定义变量
select * from table
where app={{输入app名称}}
  • Numeric Types
    bigint
    float
    double
    decimal
    numeric
  • Date/ Time Types
    timestamp
    date
translate(p_date,'-'-'') as date
--2020-10-10转换为20201010
  • String Types
  • Misc Types
    doolean
    binary
  • Complex Types
    arrays
    maps
    structs
    union

4. hive其他字符函数

  • max_pt
max_pt(`table`) --取分区最大值
  • lpad,rpad
lpad(string str,int len,string pad) --从左边开始怼str使用pad填充,最终长度len为止, 如果str长度大于pad,将去掉多余部分
  • repeat
repeat(string str, int n) --重复输出n次str
  • reverse
reverse(string str) --反转str
  • split
split(string str, string pat) --分割后以字符串形式返回

5. hive其他时间函数

  • trunc
trunc(string date, string format) --返回时间最开始的年份或者月份
trunc("2016-06-06","mm")
tuunc(current_timestamp(),'month')
  • 时间戳
from_unixtime() --将时间戳转换为format格式
unix_timestamp() --获取本地时区下的时间戳
unix_timestamp(string date) --字符串转或为时间戳
unix_timestamp(string date, string pattern) --将指定字符串格式转换成时间戳,格式不对返回0
  • datediff
datediff(string enddate,string startdate) --第一个减去第二个

6. hive其他逻辑函数

  • coalesce
coalesce(T v1, T v2,……) --返回第一个非null的值,如果全部为null,则返回null
  • nvl
nvl(T v1, T v2) --v1为null时则返回v2,负责返回v1

7. hive集合函数

  • array,map
array_contains(Array<T>,val) --如果数组Array<T>中包含val,返回true,否则返回false
size(Array<T>), size(Map<K.V>) --求数组的长度,或者map的大小(有几个字符串)
sort_array(Array<T>) --按照自然顺序对数组进行排序并返回
map_keys(Map<K.V>) --返回map的key集合
map_values(Map<K.V>) --返回map的value集合
  • explode
explode(Array) --将数组中每个元素拆为一行

8. 相关网址

  • 正则函数
    https://www.runoob.com/regexp/regexp-syntax.html
  • clickhouse
    http://saoniuhuo.com/question/detail-1911163.html
    https://www.cnblogs.com/superdrew/p/11279663.html
  • posexplode
    https://www.jianshu.com/p/cd997449dc46
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值