分享

hive时间差计算

有个小需求,计算商品发货时间和下单时间差,然后算出48小时内发货的占比

[mw_shl_code=sql,true]select sum(case when ((unix_timestamp(deliveredtime) - unix_timestamp(paytime)) / 3600) > 48
then 1 else 0
end) as deviled_countgt48hour,
sum(case when ((unix_timestamp(deliveredtime) - unix_timestamp(paytime)) / 3600) <= 48
then 1 else 0
end) as deviled_countlte48hour,
sum(case when ((unix_timestamp(deliveredtime) - unix_timestamp(paytime)) / 3600) is null
then 1 else 0
end) as deviledtimeisnull,
(sum(case when ((unix_timestamp(deliveredtime) - unix_timestamp(paytime)) / 3600) <= 48
then 1 else 0
end) / count(ordercodeofsys)) as rate_deviledlte48hour from table [/mw_shl_code]

已有(2)人评论

跳转到指定楼层
desehawk 发表于 2018-2-7 19:00:17
hive sql已结很灵活了。(unix_timestamp(deliveredtime)这是转换为Linux时间吧,deliveredtime是hive time类型?
回复

使用道具 举报

zhuqitian 发表于 2018-2-8 10:11:05
desehawk 发表于 2018-2-7 19:00
hive sql已结很灵活了。(unix_timestamp(deliveredtime)这是转换为Linux时间吧,deliveredtime是hive time ...

是的,time类型
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

推荐上一条 /2 下一条