二百七十六、ClickHouse——Hive和ClickHouse非常不同的DWS指标数据SQL语句

一、目的

在完成数据之后对业务指标进行分析,Hive和ClickHouseSQL真不一样

二、部分业务指标表

2.1 统计数据流量表1天周期

2.1.1 Hive中原有代码

2.1.1.1 Hive中建表语句
--1、统计数据流量表——动态分区——1天周期
create  table  if not exists  hurys_db.dws_statistics_volume_1day(
    device_no        string         comment '设备编号',
    scene_name       string         comment '场景名称',
    lane_no          int            comment '车道编号',
    lane_direction   string         comment '车道流向',
    section_no       int            comment '断面编号',
    device_direction string         comment '雷达朝向',
    sum_volume_day   int            comment '每天总流量',
    week_day         string         comment '周几',
    month            string         comment '月份'
)
comment '统计数据流量表——动态分区——1天周期'
partitioned by (day string)
stored as orc
;
2.1.1.2 Hive中SQL语句
--动态加载数据
insert  overwrite  table  hurys_db.dws_statistics_volume_1day  partition(day)
select
       dwd_st.device_no,
       dwd_sc.scene_name,
       dwd_st.lane_no,
       dwd_rl.lane_direction,
       dwd_st.section_no,
       dwd_rc.device_direction,
       sum(volume_sum) sum_volume_day,
       case when pmod(datediff(create_time,'2023-11-27') + 1,7) = 1 then '周一'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 2 then '周二'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 3 then '周三'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 4 then '周四'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 5 then '周五'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 6 then '周六'
      else '周日' end as week_day,
       substr(day,1,7) month,
       day
from hurys_db.dwd_statistics as dwd_st
   right join hurys_db.dwd_radar_lane as dwd_rl
             on dwd_rl.device_no=dwd_st.device_no and dwd_rl.lane_no=dwd_st.lane_no
   right join hurys_db.dwd_device_scene as dwd_ds
             on dwd_ds.device_no=dwd_st.device_no
   right join hurys_db.dwd_scene as dwd_sc
             on dwd_sc.scene_id = dwd_ds.scene_id
   right join hurys_db.dwd_radar_config as dwd_rc
             on dwd_rc.device_no=dwd_st.device_no
where dwd_st.create_time is not null   and   dwd_st.day='2024-09-05'
group by dwd_st.device_no, dwd_sc.scene_name, dwd_st.lane_no, dwd_rl.lane_direction, dwd_st.section_no, dwd_rc.device_direction, case when pmod(datediff(create_time,'2023-11-27') + 1,7) = 1 then '周一'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 2 then '周二'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 3 then '周三'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 4 then '周四'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 5 then '周五'
           when pmod(datediff(create_time,'2023-11-27') + 1,7) = 6 then '周六'
      else '周日' end, day
;

2.1.2 ClickHouse中现有代码

2.1.2.1 ClickHouse中表结构
--1、统计数据流量表——动态分区——1天周期
cre
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天地风雷水火山泽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值