Clickhouse-时间格式化,字符串转日期,月初月末年初年末,dateDiff,row_number

Clickhouse大小写敏感,字段,表名,函数

数据库默认使用开窗函数参数为关闭
sql 最后加上下这个可以不改配置用开窗
settings allow_experimental_window_functions = 1

select
-- 日期相差天数(可选month/week/day/hour/minute/second)
dateDiff('day', toDate(now()),toDate(now())+3) days,
-- 当月第一天  toStartOfYear(),toMonday(),toStartOfQuarter()
toStartOfMonth(now()) start_month,
-- 当月月末
toStartOfMonth(addMonths(now(),1))-1 end_month,
-- 当年月末
toStartOfYear(addMonths(now(),12))-1 end_year,
-- 非日期格式字符串转日期
parseDateTimeBestEffort('20220427'),
--
toString(20220427),
toFloat32('20220427'),
ifnull(null,1)

image


时间格式化

select
toDate(now()),
formatDateTime(now(),'%Y%m%d')     yyyymmdd1,
toYYYYMMDD(now())     yyyymmdd2,
toYYYYMM(now())     yyyymm ,
toYear(now())     yyyy,
toMonth(now())     mm,
formatDateTime(now(),'%d')     dd

image

字符串转日期

parseDateTimeBestEffort('20220427')    >>>>> 2022-04-27 00:00:00
-- 试了几种字符串都可以识别

image

image

image


实现row_number()
rowNumberInAllBlocks(),作用是返回此函数处理的所有块内的递增行号
但是返回的下标是从0开始,实现row_number()需要+1

image

https://blog.csdn.net/qyj19920704/article/details/126614453
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值