網站首頁 編程語言 正文
卡口轉換率
將數據導入hive,通過SparkSql編寫sql,實現不同業務的數據計算實現,主要講述車輛卡口轉換率,卡口轉化率:主要計算不同卡口下車輛之間的流向,求出之間的轉換率。
1、查出每個地區下每個路段下的車流量
select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action
此結果做為表1,方便后面錯位連接使用
2、通過錯位連接獲取每輛車的行車記錄
通過表1的結果,與自身進行錯位鏈接,并以車牌為分區,拼接經過卡口的過程
(select t1.car, t1.monitor_id, concat(t1.monitor_id, "->", t2.monitor_id) as way from ( select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action) t1 left join ( select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action) t2 on t1.car = t2.car and t1.n1 = t2.n1-1 where t2.action_time is not null)
獲取到每輛車的一個行車記錄,經過的卡口
3、獲取行車過程中的車輛數
獲取卡口1~卡口2,…等的車輛數有哪些,即拿上面的行車記錄字段進行分區在進行統計
(select s1.way, COUNT(1) sumCar from --行車過程 (select t1.car, t1.monitor_id, concat(t1.monitor_id, "->", t2.monitor_id) as way from ( select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action) t1 left join ( select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action) t2 on t1.car = t2.car and t1.n1 = t2.n1-1 where t2.action_time is not null)s1 group by way)
4、獲取每個卡口的總車輛數
獲取每個卡口最初的車輛數,方便后面拿行車軌跡車輛數/總車輛數,得出卡口之間的轉換率
select monitor_id , COUNT(1) sumall from traffic.hive_flow_action group by monitor_id
5、求出卡口之間的轉換率
select s2.way, s2.sumCar / s3.sumall zhl from ( select s1.way, COUNT(1) sumCar from --行車過程 ( select t1.car, t1.monitor_id, concat(t1.monitor_id, "->", t2.monitor_id) as way from ( select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action) t1 left join ( select car, monitor_id, action_time, ROW_NUMBER () OVER (PARTITION by car ORDER by action_time) as n1 FROM traffic.hive_flow_action) t2 on t1.car = t2.car and t1.n1 = t2.n1-1 where t2.action_time is not null)s1 group by way)s2 left join --每個卡口總車數 ( select monitor_id , COUNT(1) sumall from traffic.hive_flow_action group by monitor_id) s3 on split(s2.way, "->")[0]= s3.monitor_id
原文鏈接:https://blog.csdn.net/llAl_lAll/article/details/123134334
相關推薦
- 2024-07-13 spring-cloud和spring-cloud-alibaba的關系
- 2022-04-23 如何在String原型上封裝一個時間戳轉日期的方法詳解
- 2022-05-03 Android?Compose自定義TextField實現自定義的輸入框_Android
- 2022-10-20 Swift協議Protocol介紹_Swift
- 2022-07-28 docker容器間進行數據共享的三種實現方式_docker
- 2023-03-01 Gorm更新零值問題解決思路與過程_Golang
- 2022-07-14 設置Redis最大占用內存的實現_Redis
- 2022-06-13 C#多線程之Parallel類的用法_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支