美文网首页大数据
Clickhouse 时间格式化,字符串转日期,月初月末年初年末

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

作者: 低级开发111 | 来源:发表于2022-04-27 14:48 被阅读0次

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

    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
    

    相关文章

      网友评论

        本文标题:Clickhouse 时间格式化,字符串转日期,月初月末年初年末

        本文链接:https://www.haomeiwen.com/subject/mavcyrtx.html