首先,hive本身有一个UDF,名字是datediff.我们来看一下这个日期差计算的官方描述,(下面这个是怎么出来的): hive> desc function extended datediff; OK datediff(date1, date2) - Returns the number of days between date1 and date2 date1 and date2 are strings in the format 'yyyy-MM-dd HH:mm:ss' or 'yyy
可以用pg自带函数select extract(dow from current_date),之所以没用主要是展示一下通过数学方法计算日期的原理. drop function if exists getDateWeek(date);drop function if exists intervalDay(date);drop function if exists getMonMaxDay(integer,integer);drop function if exists getMonMaxDate(
-- 计算指定日期本周的第一天和最后一天 select day ,dayofweek(day) as dw1 ,date_add( - dayofweek(day)) as Su_s -- 周日_start ,date_add( - dayofweek(day)) as Sa_e -- 周六_end , end as dw2 ,date_add( end) as Mo_s -- 周一_start ,date_add( end) as Su_e -- 周日_end from ( select '2
Mysql 按年.季度.月分组 按月度分组: select DATE_FORMAT(i.created_at, '%Y-%m月')...................GROUP BY DATE_FORMAT(i.created_at, '%Y-%m') 按季度分组: select CONCAT(YEAR(i.created_at),'_',QUARTER(i.created_at),'Q')....................GROUP BY CONCAT(YEAR(i.created_