有个小需求,计算商品发货时间和下单时间差,然后算出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]
|