ClickHouse

clickhouse新增函数介绍

2021-09-10  本文已影响0人  郭彦超

主要针对 21.x 版本新增函数的使用进行补充说明

v21.10

CREATE FUNCTION linear_equation AS (x, k, b) -> k*x + b;
SELECT number, linear_equation(number, 2, 1) FROM numbers(3);

CREATE FUNCTION parity_str AS (n) -> if(n % 2, 'odd', 'even');
SELECT number, parity_str(number) FROM numbers(3);

select count( 1) from (
select id as create_user from app.user_model  where 1=1  and product_count>=10 and product_count<=300   
intersect 
select create_user from app.work_basic_model  where total_uv>=100 and total_uv<=350 
intersect
select create_user  from app.work_basic_model  where total_uv>=200 and total_uv<=350 
)

类似:

with 
    (select groupUniqArray(u_i)  from (select id as u_i from (select *from app.user_model  where 1=1  and product_count>=10 and product_count<=300    ) )) as u0, 
    (select groupUniqArray(create_user)  from (select create_user from (select * from app.work_basic_model  where total_uv>=100 and total_uv<=350    ) )) as u1 ,
    (select groupUniqArray(create_user)  from (select create_user from (select * from app.work_basic_model  where total_uv>=200 and total_uv<=350    ) )) as u2
select length(arrayIntersect(u0,u1,u2)) as u
select arrayJoin([1,2,3,4]) except select arrayJoin([1,2]) except select arrayJoin([4,5])
SELECT leftPad(substring(phone,-3,3), length( phone ), '*') from  (select '13126966152' phone)
--提取html中的所有去标签后的文本信息
select splitByRegexp('<[^<>]*>', x) from (select arrayJoin(['<h1>hello<h2>world</h2></h1>', 'gbye<split>bug']) x) 
select map( 'aa', 4, 'bb' , 5) as m, mapContains(m, 'aa'),mapContains(m, 'cc'), mapKeys(m), mapValues(m)
select countMatches('foo.com bar.com baz.com bam.com', '([^. ]+)\.([^. ]+)')
SELECT accurateCastOrNull(2, 'Int8'), accurateCastOrNull('ss', 'Int8')
select countSubstrings('com.foo.com.bar.com', 'com') ,countSubstringsCaseInsensitive('BaBaB', 'A')
上一篇 下一篇

猜你喜欢

热点阅读