码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Hive--07---函数简介--常用函数1


    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

    文章目录

    • 函数简介
      • 1.函数分类
    • 常用函数
      • 1. NVL()----- 空字段赋值
        • coalesce![在这里插入图片描述](https://img-blog.csdnimg.cn/c2e7e2b043a842fc80e09a4b62441c91.png)
      • 2.CASE WHEN THEN ELSE END
      • 3. CONCAT
        • 3.1 CONCAT(string A/col, string B/col…):
        • 3.2 CONCAT_WS(separator, str1, str2,...):
        • 3.3 COLLECT_LIST(col):
        • 3.4 COLLECT_SET(col):
    • 常用函数详细


    函数简介

    1.函数分类

    • UDF—普通函数
    • UDAF—聚合函数
    • UDTF—炸裂函数

    在这里插入图片描述

    在这里插入图片描述

    常用函数

    1. NVL()----- 空字段赋值

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    coalesce在这里插入图片描述

    2.CASE WHEN THEN ELSE END

    在这里插入图片描述
    在这里插入图片描述

    在这里插入图片描述

    3. CONCAT

    3.1 CONCAT(string A/col, string B/col…):

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    3.2 CONCAT_WS(separator, str1, str2,…):

    在这里插入图片描述
    在这里插入图片描述

    3.3 COLLECT_LIST(col):

    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    3.4 COLLECT_SET(col):

    在这里插入图片描述

    在这里插入图片描述
    在这里插入图片描述

    常用函数详细

    常用日期函数
    unix_timestamp:返回当前或指定时间的时间戳	
    select unix_timestamp();
    select unix_timestamp("2020-10-28",'yyyy-MM-dd');
    
    from_unixtime:将时间戳转为日期格式
    select from_unixtime(1603843200);
    
    current_date:当前日期
    select current_date;
    
    current_timestamp:当前的日期加时间
    select current_timestamp;
    
    to_date:抽取日期部分
    select to_date('2020-10-28 12:12:12');
    
    year:获取年
    select year('2020-10-28 12:12:12');
    
    month:获取月
    select month('2020-10-28 12:12:12');
    
    day:获取日
    select day('2020-10-28 12:12:12');
    
    hour:获取时
    select hour('2020-10-28 12:12:12');
    
    minute:获取分
    select minute('2020-10-28 12:12:12');
    
    second:获取秒
    select second('2020-10-28 12:12:12');
    
    weekofyear:当前时间是一年中的第几周
    select weekofyear('2020-10-28 12:12:12');
    
    dayofmonth:当前时间是一个月中的第几天
    select dayofmonth('2020-10-28 12:12:12');
    
    months_between: 两个日期间的月份
    select months_between('2020-04-01','2020-10-28');
    
    add_months:日期加减月
    select add_months('2020-10-28',-3);
    
    datediff:两个日期相差的天数
    select datediff('2020-11-04','2020-10-28');
    
    date_add:日期加天数
    select date_add('2020-10-28',4);
    
    date_sub:日期减天数
    select date_sub('2020-10-28',-4);
    
    last_day:日期的当月的最后一天
    select last_day('2020-02-30');
    
    date_format(): 格式化日期
    select date_format('2020-10-28 12:12:12','yyyy/MM/dd HH:mm:ss');
    
    常用取整函数
    round: 四舍五入
    select round(3.14);
    select round(3.54);
    
    ceil:  向上取整
    select ceil(3.14);
    select ceil(3.54);
    
    floor: 向下取整
    select floor(3.14);
    select floor(3.54);
    
    常用字符串操作函数
    upper: 转大写
    select upper('low');
    
    lower: 转小写
    select lower('low');
    
    length: 长度
    select length("atguigu");
    
    trim:  前后去空格
    select trim(" atguigu ");
    
    lpad: 向左补齐,到指定长度
    select lpad('atguigu',9,'g');
    
    rpad:  向右补齐,到指定长度
    select rpad('atguigu',9,'g');
    
    regexp_replace:使用正则表达式匹配目标字符串,匹配成功后替换!
    SELECT regexp_replace('2020/10/25', '/', '-');
    
    集合操作
    size: 集合中元素的个数
    select size(friends) from test3;
    
    map_keys: 返回map中的key
    select map_keys(children) from test3;
    
    map_values: 返回map中的value
    select map_values(children) from test3;
    
    array_contains: 判断array中是否包含某个元素
    select array_contains(friends,'bingbing') from test3;
    
    sort_array: 将array中的元素排序
    select sort_array(friends) from test3;
    
    grouping_set:多维分析
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
  • 相关阅读:
    使用LVM方式创建linux文件系统,详细教程
    [极致用户体验] 微信设置大字号后,iOS加载网页时闪动怎么办?
    Mongodb单机、复制集Replica Sets、分片集群Shard Cluster安装详解
    Structured Streaming系列-6、事件时间窗口分析
    动机:关于如何获得和保持动力的科学指南
    利用地质年代图谱精准判读文献中的地质时间
    Python+selenium爬虫启用chrome无头浏览器
    Windows 下 Sublime Text 3.2.2 下载及配置
    Android 调试桥 (adb) 使用教程/示例
    AI 实战篇 |十分钟学会【动物识别】,快去寻找身边的小动物试试看吧【送书】
  • 原文地址:https://blog.csdn.net/weixin_48052161/article/details/125398546
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号