ck 使用的时候会有很多坑,或者说是使用小技巧(临时先放着)
查询DDL
1 | -- 2024-03-22 17:09:44 |
表:创建/插入/删除
1 | select * from aaa; |
聚合函数
1 | -- 查询字段 可group,也可max/min/any |
数值计算
1 | -- 四舍五入 保留几位小数 设置默认值 |
字符串拼接
1 | -- 两个字符串拼接 => "a b" |
字符串替换/分割/一行变多行
1 | -- SQL解释:下面 xxx 为占位符 |
json解析
1 | select * from system.functions where name like '%visitParamExtractString%'; |
map函数
1 | select * from system.functions where name like '%map%'; |
日期
1 | -- 相关日期函数(这里能查出来的,官方文档不一定有) |
排名函数
好多人说,为什么ck没有排名函数,其实有的,网上都没有给出相关案例。
window-functions — ClickHouse
1 | -- 排名函数 |
WITH语法
1 | -- 2023-01-13...14.02.10 ck 多with语法.txt |
未分类
上周一
1 | -- 实际使用 |
平均首单时间
1 | -- 实际使用 |
case when
1 | -- 实际使用 |
左关联默认值
1 | -- 默认值显示 0 |
ifNull 字符串默认值
1 | -- 默认字符串 0 |
if 等同于case when
1 | if(a is null, 0, a) |
自定义函数
1 | select * from system.functions where name like '%Div%' |
集群
1 | -- 删除函数 - 集群 |
分组取第一条
1 | with xxx as ( |
合并数组/数组拆分
1 | with l as ( |
arrayFilter/arrayMap
1 | with tmp as ( |
元组tuple
1 | -- 2024-03-21 16:18 prompt.yml |
数组array
1 | -- 合并为数组(聚合函数) ===> groupUniqArray、groupUniqArrayIf |
多字段相加
1 | -- null + 0 结果为 null |