-
PART1 时间差
阅读:https://www.jianshu.com/p/d01d095edc4a
1 将时间转换成时间戳
2 将时间戳相减
3 注意单位(分钟、毫秒)
E.x. CAST((unix_timestamp(rt.refund_ticket_time) - unix_timestamp(rt.create_time)) / 60 AS int)<=30
-
PART 2 日期格式转换
阅读:https://blog.csdn.net/weixin_37536446/article/details/82419601
在解析埋点数据时会遇到两种不同的日期格式:yyyymmdd和yyyy-mm-dd,此类型之间的转换主要有两种思路:
-
第一种方法:from_unixtime+unix_timestamp
--20180905转成2018-09-05
select from_unixtime(unix_timestamp('20180905','yyyymmdd'),'yyyy-mm-dd')
from dw.ceshi_data
--结果如下:
2018-09-05
--2018-09-05转成20180905
select from_unixtime(unix_timestamp('2018-09-05','yyyy-mm-dd'),'yyyymmdd')
from dw.ceshi_data
--结果如下:
20180905
- 第二种方法:substr + concat
--20180905转成2018-09-05
select concat(substr('20180905',1,4),'-',substr('20180905',5,2),'-',substr('20180905',7,2)) from dw.ceshi_data
结果如下:
2018-09-05
--2018-09-05转成20180905
select concat(substr('2018-09-05',1,4),substr('2018-09-05',6,2),substr('2018-09-05',9,2)) from dw.ceshi_data
结果如下:
20180905