1. 聚合函数
- 指定列值的数目:count()
- 指定列值求和:sum()
- 指定列的最大值:max()
- 指定列的最小值:min()
- 指定列的平均值:avg()
- 非空集合总体变量函数:var_pop(col)
- 非空集合样本变量函数:var_samp (col)
- 总体标准偏离函数:stddev_pop(col)
- 分位数函数:percentile(BIGINT col, p)
- 中位数函数:percentile(BIGINT col, 0.5)
2. 关系运算
- A LIKE B:LIKE比较,如果字符串A符合表达式B 的正则语法,则为TRUE
- A RLIKE B:JAVA的LIKE操作,如果字符串A符合JAVA正则表达式B的正则语法,则为TRUE
- A REGEXP B:功能与RLIKE相同
3. 数学运算
支持所有数值类型:加(+)、减(-)、乘(*)、除(/)、取余(%)、位与(&)、位或(|)、位异或(^)、位取反(~)
4. 逻辑运算
支持:逻辑与(and)、逻辑或(or)、逻辑非(not)
5. 数值运算
- 取整函数:round(double a)
- 指定精度取整函数:round(double a, int d)
- 向下取整函数:floor(double a)
- 向上取整函数:ceil(double a)
- 取随机数函数:rand(),rand(int seed)
- 自然指数函数:exp(double a)
- 以10为底对数函数:log10(double a)
- 以2为底对数函数:log2()
- 对数函数:log()
- 幂运算函数:pow(double a, double p)
- 开平方函数:sqrt(double a)
- 二进制函数:bin(BIGINT a)
- 十六进制函数:hex()
- 绝对值函数:abs()
- 正取余函数:pmod()
6. 条件函数
- if
- case when
- coalesce(c1,c2,c3)
- nvl(c1,c2)
7. 日期函数
- 获得当前时区的UNIX时间戳: unix_timestamp()
- 时间戳转日期函数:from_unixtime()
- 日期转时间戳:unix_timestamp(string date)
- 日期时间转日期函数:to_date(string timestamp)
- 日期转年函数:year(string date)
- 日期转月函数:month (string date)
- 日期转天函数: day (string date)
- 日期转小时函数: hour (string date)
- 日期转分钟函数:minute (string date)
- 日期转秒函数: second (string date)
- 日期转周函数: weekofyear (string date)
- 日期比较函数: datediff(string enddate, string startdate)
- 日期增加函数: date_add(string startdate, int days)
- 日期减少函数:date_sub (string startdate, int days)
8. 字符串函数
- 字符串长度函数:length(string A)
- 字符串反转函数:reverse(string A)
- 字符串连接函数: concat(string A, string B…)
- 带分隔符字符串连接函数:concat_ws(string SEP, string A, string B…)
- 字符串截取函数: substr(string A, int start, int len)
- 字符串转大写函数: upper(string A)
- 字符串转小写函数:lower(string A)
- 去空格函数:trim(string A)
- 左边去空格函数:ltrim(string A)
- 右边去空格函数:rtrim(string A)
- 正则表达式替换函数:regexp_replace(string A, string B, string C)
- 正则表达式解析函数: regexp_extract(string subject, string pattern, int index)
- URL解析函数:parse_url(string urlString, string partToExtract [, string keyToExtract]) 返回值: string
- json解析函数:get_json_object(string json_string, string path)
- 空格字符串函数:space(int n)
- 重复字符串函数:repeat(string str, int n)
- 首字符ascii函数:ascii(string str)
- 左补足函数:lpad(string str, int len, string pad)
- 右补足函数:rpad(string str, int len, string pad)
- 分割字符串函数: split(string str, string pat)
- 集合查找函数: find_in_set(string str, string strList)
9. 窗口函数
- 分组求和函数:sum(pv) over(partition by cookieid order by createtime) 有坑,加不加 order by 差别很大,具体详情在下面第二部分。
- 分组内排序,从1开始顺序排:ROW_NUMBER() 如:1234567
- 分组内排序,排名相等会在名次中留下空位:RANK() 如:1233567
- 分组内排序,排名相等不会在名次中留下空位:DENSE_RANK() 如:1233456
- 有序的数据集合平均分配到指定的数量(num)个桶中:NTILE()
- 统计窗口内往上第n行值:LAG(col,n,DEFAULT)
- 统计窗口内往下第n行值:LEAD(col,n,DEFAULT)
- 分组内排序后,截止到当前行,第一个值:FIRST_VALUE(col)
分组内排序后,截止到当前行,最后一个值: LAST_VALUE(col)
小于等于当前值的行数/分组内总行数:CUME_DIST()
