hive—常用的函数整理

server/2025/2/23 1:32:15/

1、size(split(...))函数用于计算分割后字符串数组的长度

实例1):由客户编号列表计算客户编号个数

--数据准备
with tmp_test01 as (
select 'tag074445270' tag_id,'202501'busi_mon , '012399931003,012399931000' index_val
union all
select 'tag074445271' tag_id,'202501'busi_mon , '037100006340,030600050969,030600012604' index_val
union all
select 'tag074445271' tag_id,'202501'busi_mon , '' index_val
)--计算客户编号个数
select tag_id, busi_mon,index_val,
COALESCE(SUM(case when length(trim(index_val)) >0 then size(split(index_val, ',')) else 0 end ), 0) AS index_val_0, --计算结果
size(split(index_val,",")) DD,  --数组长度
split(index_val,",") SS --字符串分隔情况
from tmp_test01
group by tag_id, busi_mon,index_val

注:1、空字符串处理‌:如果分割的字段串是空字符串(例如a=''),size(split(a, ','))的结果为1,因为空字符串被视为一个元素‌;

2、null值处理‌:如果分割的字段串是null(例如a is null),size(split(a, ','))的结果为-1

2、LPAD(string, length, pad_string) :在字符串左侧填充指定字符以达到指定长度的函数

实例1):部门编号补足4位数,客户编号补足12位数

select
LPAD(KH,12,'0')                   as Pty_Id                       --客户当事人编号
,LPAD(YYB,4,'0')                   as Inr_Org_Id                   --内部机构编号
from table_name


http://www.ppmy.cn/server/169998.html

相关文章

P8752 [蓝桥杯 2021 省 B2] 特殊年份——string提取索引转换为值

这里写目录标题 链接题目代码大佬解答string提取索引转换为值 链接 P8752 [蓝桥杯 2021 省 B2] 特殊年份 题目 代码 #include <iostream> #include <vector> #include <string> #include <algorithm> #include <math.h> #include <queue&g…

《Operating System Concepts》阅读笔记:p62-p75

《Operating System Concepts》学习第 10 天&#xff0c;p62-p75 总结&#xff0c;总计 14 页。 一、技术总结 1. system call (1) 定义 The primary interface between processes and the operating system, providing a means to invoke services made available by th…

51单片机-按键

1、独立按键 1.1、按键介绍 轻触开关是一种电子开关&#xff0c;使用时&#xff0c;轻轻按开关按钮就可使开关接通&#xff0c;当松开手时&#xff0c;开关断开。 1.2、独立按键原理 按键在闭合和断开时&#xff0c;触点会存在抖动现象。P2\P3\P1都是准双向IO口&#xff0c;…

✨ 索引有哪些缺点以及具体有哪些索引类型

索引的定义与原理 索引是数据库中用于提高数据检索效率的数据结构。它就像是书籍的目录&#xff0c;通过目录可以快速定位到所需内容的页码&#xff0c;而在数据库中&#xff0c;索引可以帮助数据库系统快速找到符合查询条件的数据行&#xff0c;而不必对整个表进行扫描。 其…

可编辑112页PPT | DeepSeek行业应用实践报告

荐言分享&#xff1a;DeepSeek&#xff0c;作为一种前沿的人工智能技术&#xff0c;自其发布以来&#xff0c;已在多个行业领域展现出广泛的应用潜力和实践价值。本报告旨在全面介绍DeepSeek的技术特点、行业应用实践以及其对未来行业发展的深远影响。 DeepSeek-R1&#xff0c;…

【python】网页批量转PDF

安装wkhtmltopdf 网站&#xff1a;wkhtmltopdf wkhtmltopdf http://www.baidu.com/ D:website1.pdf 安装pdfkit库 pip install pdfkit 批量转换代码 import os import pdfkit path_wkthmltopdf rE:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe config pdfkit.configu…

wps中的js开发

严格区分大小写 /*** learn_js Macro*/ function test() {Range(D7).Value2Selection.Value2; // Selection.formula "100" }function Workbook_SheetSelectionChange(Sh, Target) {if(Sh.Name Sheet1) {test();}}function test2() {// 把I4单元格及其周边有数的单…

跨中心模型自适应牙齿分割|文献速递-医学影像人工智能进展

Title 题目 Cross-center Model Adaptive Tooth segmentation 跨中心模型自适应牙齿分割 01 文献速递介绍 三维&#xff08;3D&#xff09;口腔内扫描牙齿模型的自动、准确分割是计算机辅助正畸治疗不可或缺的先决条件。具体而言&#xff0c;口腔内扫描&#xff08;IOS&am…