答案 0 :(得分:1)
将时间戳转换为秒,然后减去,将结果除以3600得到小时,用例+计数按范围计算,如下所示:
select count(case when diff_hrs >24 then 1 end) as more_24,
count(case when diff_hrs <=24 then 1 end) as less_than_24,
...
count(case when diff_hrs >=2 and diff_hrs <=3 then 1 end) as hrs_2_to_3,
...
from
(
select
abs(unix_timestamp(dts) - unix_timestamp(dts-eat)))/60/60 as diff_hrs
from table
)s;