Hive:trunc函数

一、日期
TRUNC函数为指定元素而截去的日期值。

其具体的语法格式:TRUNC(date[,fmt])

其中:

date 一个日期值

fmt 日期格式

sql 复制代码
-- 如果当日日期是:2022-11-02
select trunc('2022-11-02','MM')        --2022-11-01        返回当月第一天
select trunc('2022-11-02','YY')        --2022-01-01        返回当年第一天
select trunc('2022-11-02','YYYY')       --2022-01-01        返回当年第一天
select trunc('2022-11-02','Q')         --2022-10-01        返回当前季度第一天

二、数字TRUNC(number,num_digits)
Number 需要截尾取整的数字。

Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。

TRUNC()函数截取时不进行四舍五入

sql 复制代码
select trunc(123.458)        --123
select trunc(123.458,0)       --123
select trunc(123.458,1)        --123.4
select trunc(123.458,-1)       --120
select trunc(123.458,-4)       --0
select trunc(123.458,4)        --123.458
select trunc(123)           --123
select trunc(123,1)          --123
相关推荐
YF云飞12 分钟前
数据仓库进化:Agent驱动数智化新范式
数据仓库·人工智能·ai
KANGBboy3 天前
hive udf 执行一次调用多次问题
数据仓库·hive·hadoop
来杯雀巢咖啡4 天前
ubantu安装配置hive
数据仓库·hive·hadoop
chad__chang5 天前
HIVE的Window functions窗口函数【二】
数据仓库·hive·hadoop
張萠飛5 天前
hive on tez为什么写表时,要写临时文件到hdfs目录
hive·hadoop·hdfs
秉寒-CHO6 天前
5w2h构建数据仓库与sow
大数据·数据仓库
白日与明月6 天前
Hive中的with子句
数据仓库·hive
步行cgn7 天前
Servlet 注解:简化配置的完整指南
hive·hadoop·servlet
喻师傅8 天前
横扫SQL面试——流量与转化率分类
大数据·数据仓库·sql