網站首頁 編程語言 正文
卡口轉換率
將數據導入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
相關推薦
- 2022-09-18 Python中np.linalg.norm()用法實例總結_python
- 2022-12-23 一文帶你了解Android中的網絡請求_Android
- 2022-08-19 element-plus中的el-select回顯錯誤如何解決?
- 2022-04-15 python實現請求數據包簽名_python
- 2022-07-19 Linux硬盤分區步驟詳解
- 2022-11-09 React?錯誤邊界Error?Boundary使用示例解析_React
- 2022-06-02 Docker部署項目完全使用指南(小結)_docker
- 2023-07-26 vite中的glob-import批量導入
- 最近更新
-
- 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同步修改后的遠程分支