当前位置:网站首页>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, Reusesum
Sum 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;
边栏推荐
- Neon Optimization: an instruction optimization case of matrix transpose
- golang中的WaitGroup实现原理
- C# 计算农历日期方法 2022
- 从底层结构开始学习FPGA----FIFO IP的定制与测试
- [100 cases of JVM tuning practice] 05 - Method area tuning practice (Part 2)
- 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
- C语言实例_4
- 负载均衡性能参数如何测评?
- boot - prometheus-push gateway 使用
- 1123. 最深叶节点的最近公共祖先
猜你喜欢
go-zero微服务实战系列(九、极致优化秒杀性能)
Analysis of mutex principle in golang
Byte P7 professional level explanation: common tools and test methods for interface testing, Freeman
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
微信公众号发送模板消息
Force buckle 1037 Effective boomerang
UI control telerik UI for WinForms new theme - vs2022 heuristic theme
2022 Google CTF segfault Labyrinth WP
ARM裸板调试之JTAG原理
2022 Google CTF SEGFAULT LABYRINTH wp
随机推荐
golang中的WaitGroup实现原理
Lldp compatible CDP function configuration
Realize incremental data synchronization between MySQL and ES
Data type of pytorch tensor
Spark TPCDS Data Gen
Informatics Orsay Ibn YBT 1172: find the factorial of n within 10000 | 1.6 14: find the factorial of n within 10000
云呐|工单管理软件,工单管理软件APP
How to manage distributed teams?
搭建【Redis in CentOS7.x】
字节P7专业级讲解:接口测试常用工具及测试方法,福利文
Oracle:CDB限制PDB资源实战
负载均衡性能参数如何测评?
第三方跳转网站 出现 405 Method Not Allowed
docker 方法安装mysql
Dark horse notes - create immutable sets and streams
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
系统休眠文件可以删除吗 系统休眠文件怎么删除
LeetCode:1175. 质数排列
力扣1037. 有效的回旋镖
[chip scheme design] pulse oximeter