当前位置:网站首页>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;
边栏推荐
- Gnet: notes on the use of a lightweight and high-performance go network framework
- What does security capability mean? What are the protection capabilities of different levels of ISO?
- Add the applet "lazycodeloading": "requiredcomponents" in taro,
- 子网划分、构造超网 典型题
- Match VIM from zero (0) -- Introduction to vimscript
- 如何管理分布式团队?
- Lldp compatible CDP function configuration
- C语言实例_2
- go-zero微服务实战系列(九、极致优化秒杀性能)
- C language - array
猜你喜欢

Dark horse notes - create immutable sets and streams

力扣1037. 有效的回旋镖
![[case sharing] basic function configuration of network loop detection](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[case sharing] basic function configuration of network loop detection

Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform

AI automatically generates annotation documents from code

Typical problems of subnet division and super network construction

2022 Google CTF SEGFAULT LABYRINTH wp

How to manage distributed teams?

系统休眠文件可以删除吗 系统休眠文件怎么删除

The MySQL database in Alibaba cloud was attacked, and finally the data was found
随机推荐
系统休眠文件可以删除吗 系统休眠文件怎么删除
[JS] obtain the N days before and after the current time or the n months before and after the current time (hour, minute, second, year, month, day)
NEON优化:性能优化常见问题QA
Spark TPCDS Data Gen
[Niuke] b-complete square
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
域分析工具BloodHound的使用说明
UI control telerik UI for WinForms new theme - vs2022 heuristic theme
Let's see through the network i/o model from beginning to end
Taro 小程序开启wxml代码压缩
[signal and system]
前置机是什么意思?主要作用是什么?与堡垒机有什么区别?
搭建【Redis in CentOS7.x】
ARM裸板调试之JTAG原理
MySQL中回表的代价
Google发布安全更新,修复Chrome中已被利用的0 day
Dynamic planning idea "from getting started to giving up"
HMM 笔记
NEON优化:矩阵转置的指令优化案例
【C语言进阶篇】指针的8道笔试题