当前位置:网站首页>Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
2022-07-07 01:26:00 【Persistence is an attitude】
ClickHouse Field grouping aggregation 、 Query according to the granularity of any time period SQL

demand
- Basic data warehousing , You need to do some aggregation according to the fields
- Existing intersection passing data , There are various models , It is necessary to count the total flow and the flow of each model , To return together
- Existing passing data , It needs different granularity according to time , Count the traffic flow , Achieve different time granularity summation ,5 minute 、10 minute 、 Half an hour 、 A month 、 A year will do
solve
Use if and sum
- Mainly used
if, The eligible conditions are 1, The nonconformity is 0, ReusesumSum up
select
count(1) as " Total discharge ",
SUM(if(vehicle_type = 'PEDESTRIAN', 1, 0)) as " Pedestrian flow ",
SUM(if(vehicle_type = 'NON_MOTORIZED', 1, 0)) as " Non motor vehicle flow ",
SUM(if(vehicle_type = 'LIGHT_DUTY', 1, 0)) as " Small traffic flow ",
SUM(if(vehicle_type = 'MEDIAN_SIZED', 1, 0)) as " Medium traffic flow ",
SUM(if(vehicle_type = 'OVERSIZE', 1, 0)) as " Large traffic flow "
from
passing_vehicle
where
exist_time > 0
and time_stamp > toDateTime('2022-06-30 11:00:00')
and time_stamp < toDateTime('2022-06-30 15:00:00')
;
Use toStartOfInterval
select
toStartOfInterval(time_stamp , INTERVAL 30 minute) as half_hour,
count(1) as " Total discharge ",
SUM(if(vehicle_type = 'PEDESTRIAN', 1, 0)) as " Pedestrian flow ",
SUM(if(vehicle_type = 'NON_MOTORIZED', 1, 0)) as " Non motor vehicle flow ",
SUM(if(vehicle_type = 'LIGHT_DUTY', 1, 0)) as " Small traffic flow ",
SUM(if(vehicle_type = 'MEDIAN_SIZED', 1, 0)) as " Medium traffic flow ",
SUM(if(vehicle_type = 'OVERSIZE', 1, 0)) as " Large traffic flow "
from
passing_vehicle
where
exist_time > 0
and time_stamp > toDateTime('2022-06-30 11:00:00')
and time_stamp < toDateTime('2022-06-30 15:00:00')
group by
half_hour,
order by
half_hour;
边栏推荐
- Docker method to install MySQL
- 域分析工具BloodHound的使用说明
- 从底层结构开始学习FPGA----FIFO IP的定制与测试
- How to manage distributed teams?
- pyflink的安装和测试
- 系统休眠文件可以删除吗 系统休眠文件怎么删除
- 云呐-工单管理制度及流程,工单管理规范
- LeetCode:1175. 质数排列
- Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which
- 云呐|工单管理软件,工单管理软件APP
猜你喜欢
![[Niuke] b-complete square](/img/bd/0812b4fb1c4f6217ad5a0f3f3b8d5e.png)
[Niuke] b-complete square

JTAG debugging experience of arm bare board debugging
![[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)](/img/40/dc45df3cd3ee7642277eff899bc6aa.png)
[100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)

黑马笔记---创建不可变集合与Stream流

Tensorflow GPU installation

Make Jar, Not War

Come on, don't spread it out. Fashion cloud secretly takes you to collect "cloud" wool, and then secretly builds a personal website to be the king of scrolls, hehe

域分析工具BloodHound的使用说明

Transformation transformation operator

Go zero micro service practical series (IX. ultimate optimization of seckill performance)
随机推荐
2022 Google CTF SEGFAULT LABYRINTH wp
Spark TPCDS Data Gen
第三方跳转网站 出现 405 Method Not Allowed
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
Installation of torch and torch vision in pytorch
How to manage distributed teams?
Oracle: Practice of CDB restricting PDB resources
数据手册中的词汇
Supersocket 1.6 creates a simple socket server with message length in the header
736. Lisp 语法解析 : DFS 模拟题
golang中的WaitGroup实现原理
405 method not allowed appears when the third party jumps to the website
C# 计算农历日期方法 2022
Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
「笔记」折半搜索(Meet in the Middle)
2022 Google CTF segfault Labyrinth WP
力扣1037. 有效的回旋镖
树莓派/arm设备上安装火狐Firefox浏览器
Can the system hibernation file be deleted? How to delete the system hibernation file
Dark horse notes - create immutable sets and streams