如何检查几对雷达之间的流量?

时间:2017-08-03 14:53:12

标签: sql hive hiveql

我在Hive中有以下工作查询(请参阅previous question)。它返回雷达A21B15之间通过路段的平均骑行次数。

select  count(*) / count(distinct to_date(datetime))    as trips_per_day

from   (select  radar_id
               ,datetime
               ,lead(radar_id) over w  as next_radar_id
               ,lead(datetime) over w  as next_datetime                    

        from    mytable

        where   radar_id in ('A21','B15')

        window  w as 
                (
                    partition by  car_id
                    order by      datetime
                )
        ) t

where   radar_id        = 'A21'
    and next_radar_id   = 'B15'
    and to_unix_timestamp(datetime) + 30*60 > to_unix_timestamp(next_datetime)
;

我想扩展此查询,以便检查路由A21->B15B15->A22D12->E23。查询应该输出如下所示的表而不是单个数字:

radar_start    radar_end   avg_trips_per_day
A21            B15         1.5
B15            A22         ...
...

如何通过雷达对?

0 个答案:

没有答案