-- 一、聚合函数
--1、 uniq 这个是近似的去重
--1.1、查询 ad_id、day 的 uid 用户数;结果 389124
select uniq(uid) as num
from `source`.report_data_ad
where ad_id = '887606861'
and day = '2021-11-08'
--1.2、查询 ad_id、day 的 adac =8 的 uid 用户数;结果 313883
select uniq(uid,adac = 8) as num
from `source`.report_data_ad
where ad_id = '887606861'
and day = '2021-11-09'
--2、uniqExact 这个是精确的去重类似于 count 统计
--2.1、查询 ad_id、day 的 uid 用户数;结果 386968
select uniqExact(uid) as num
from `source`.report_data_ad
where ad_id = '887606861'
and day = '2021-11-08'
-- 相当于一下查询;结果 386968
select count(1)
from (
select count(uid) as num
from `source`.report_data_ad
where ad_id = '887606861'
and day = '2021-11-08'
group by uid
)
--2.2、查询 ad_id、day 的 adac =8 的 uid 用户数;结果 314544
select uniqExact(uid,adac = 8) as num
from `source`.report_data_ad
where ad_id = '887606861'
and day = '2021-11-09'
--2、uniqExactIf 查询结果:5258
select uniqExactIf(uid,adac = 8) as num
from `source`.report_data_ad
where ad_id = '887606861'
and day = '2021-11-08'
-- 3、uniqState、uniqMerge,两个函数一起使用,uniqState聚合统计后二进制存储,uniqMerge来读取
-- 二、类型转换行数
-- 1、多行转换一行 groupArray
-- 日期时间格式化 formatDateTime(toDateTime(timestamp),'%Y-%m-%d %H:%M:%S')
-- any(field) 返回这个字段的任意一条
--2、编码函数
-- base64Encode 将字符编码为base64字符串
-- base64Encode 解码base字符串,如果出错则抛出异常
-- tryBase64Decode 解码base字符串,如果出错则返回空
-- endsWith(s,后缀) 返回是否以指定的后缀结尾。如果字符串以指定的后缀结束,则返回1,否则返回0。
-- startsWith(s,前缀) 返回是否以指定的前缀开头。如果字符串以指定的前缀开头,则返回1,否则返回0。
-- trimLeft(s) 返回一个字符串,用于删除左侧的空白字符。
-- trimRight(s) 返回一个字符串,用于删除右侧的空白字符
-- trimBoth(s) 返回一个字符串,用于删除任一侧的空白字符
--2、统计函数
-- uniqExactIf(colum,if) 统计字段colum,在满足 if 条件时的数量
-- 三、机器学习函数
-- evalMLMethod 预测 使用拟合回归模型的预测请使用evalMLMethod函数。 请参阅 linearRegression 中的链接。
-- 随机线性回归 stochasticLinearRegression 聚合函数使用线性模型和MSE损失函数实现随机梯度下降法。 使用 evalMLMethod 来预测新数据。
-- stochasticLogisticRegression 聚合函数实现了二元分类问题的随机梯度下降法。 使用 evalMLMethod 来预测新数据。
-- 一维线性回归
simpleLinearRegression(x, y)
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [0, 1, 2, 3])
(1,0)
SELECT arrayReduce('simpleLinearRegression', [0, 1, 2, 3], [3, 4, 5, 6])
(1,3)
-- 四 geo 经纬度计算
-- 计算两个经纬度之间的距离,单位米,greatCircleDistance(lon1Deg, lat1Deg, lon2Deg, lat2Deg)
最后修改于 2021-11-11 18:19:11
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付

