首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    一个sql生成hive日期维度表

    set hive.execution.engine=tez; with dates as ( select date_add("2010-01-01", a.pos) as d from (select posexplode(split(repeat("o", datediff("2030-12-31", "2010-01-01")), "o"))) a ) insert overwrite table dim.dim_date select     d   , date_format(d, 'yyyyMMdd000000') as to_pt            -- 指定分区格式   , date_format(d, 'yyyyMMdd')       as date_yyyymmdd   , trunc(d,'MM')                    as month_first_day    , last_day(d)                      as month_last_day   , date_format(last_day(d),'yyyyMMdd000000')   as month_last_pt   , date_format(d, 'yyyyMM')  as month_yyyymm   , date_format(d, 'yyyy-MM') as month_yyyy_mm   , month(d) as month   , date_format(d, 'u') as week   , date_format(d, 'E') as week_long      , weekofyear(d) as week_of_year   , year(d) as year   , floor(substr(d,6,2)/3.1)*3+1 as quarter   -- , concat_group('"',date_format(d, 'yyyyMM'),'"') as date_yyyymmdd_list   -- 低版本hive group_concat 不可用 from dates

    03

    sql的日期格式化「建议收藏」

    %a 缩写星期名 %b 缩写月名 %c 月,数值 %D 带有英文前缀的月中的天 %d 月的天,数值(00-31) %e 月的天,数值(0-31) %f 微秒 %H 小时 (00-23) %h 小时 (01-12) %I 小时 (01-12) %i 分钟,数值(00-59) %j 年的天 (001-366) %k 小时 (0-23) %l 小时 (1-12) %M 月名 %m 月,数值(00-12) %p AM 或 PM %r 时间,12-小时(hh:mm:ss AM 或 PM) %S 秒(00-59) %s 秒(00-59) %T 时间, 24-小时 (hh:mm:ss) %U 周 (00-53) 星期日是一周的第一天 %u 周 (00-53) 星期一是一周的第一天 %V 周 (01-53) 星期日是一周的第一天,与 %X 使用 %v 周 (01-53) 星期一是一周的第一天,与 %x 使用 %W 星期名 %w 周的天 (0=星期日, 6=星期六) %X 年,其中的星期日是周的第一天,4 位,与 %V 使用 %x 年,其中的星期一是周的第一天,4 位,与 %v 使用 %Y 年,4 位 %y 年,2 位

    02

    mysql 自定义函数的常见语法

    CREATE  FUNCTION `one_day_N`(lastAcctDate DATETIME, freqCounter DECIMAL, startDate DATETIME) RETURNS INT(11)     COMMENT '计算一天N次的计费次数' BEGIN    DECLARE return_val INT DEFAULT 0;    DECLARE HOUR INT;    DECLARE CHOUR INT;    DECLARE start_time DATETIME;    IF lastAcctDate IS NULL      THEN   SELECT get_start_time(lastAcctDate,startDate) INTO start_time;           SELECT DATE_FORMAT(start_time , '%H') INTO HOUR;    IF HOUR<12 THEN   SET return_val=freqCounter;    ELSE SET return_val=freqCounter/2;    END IF;     ELSE       IF DATE_FORMAT(NOW(),'%Y-%m-%d')!=DATE_FORMAT(lastAcctDate,'%Y-%m-%d') THEN            IF freqCounter=1              THEN                SET return_val=1;           ELSE            SELECT DATE_FORMAT(NOW(),'%H') INTO CHOUR;    IF CHOUR<12    THEN                  SET return_val=freqCounter/2;             ELSE                   SET return_val=freqCounter;             END IF;           END IF;       ELSE  SET return_val=0;       END IF;     END IF; RETURN return_val;

    02
    领券