- 字符串拼接
concat
: 直接对传入的参数拼接concat_ws
: 使用特点字符串来拼接传入的参数
Select CONCAT('Ram','is','a','good','student') AS 'Example of CONCAT()';
+---------------------+
| Example of CONCAT() |
+---------------------+
| Ramisagoodstudent |
+---------------------+
Select CONCAT_WS(' ','Ram','is','a','good','student') AS 'Example of CONCAT_WS()';
+------------------------+
| Example of CONCAT_WS() |
+------------------------+
| Ram is a good student |
+------------------------+
- 列转行
把多条数据,并到一个list当中。
collect_set()
会对搜集的数据进行去重;
collect_list()
会对搜集的数据不去重。
collect_list(sku_code) as sku_code_list
collect_set(sku_code) as sku_code_list
- 计算中位数
percentile(cast(tad_store as BIGINT), 0.5) as tad_median
- 日期函数
from_unixtime(unix_timestamp('${dt}' ,'yyyyMMdd'), 'yyyy-MM-dd'), -- yyyyMMdd to yyyy-MM-dd
date_format('${date}','yyyyMMdd') -- yyyy-MM-dd to yyyyMMdd
- COALESCE 函数
COALESCE(field1, field2, … , fieldn)
- 依序检验每个参数,当参数不为空的时候,选择该参数,结束循环。
row param1 param2 param3
1 1048-02-15 1048-03-01 1048-04-01
2 NULL 1049-08-29 1049-10-29
3 NULL NULL 1050-07-01
COALESCE(param1, param2, param3)
返回值为
row result
1 1048-02-15
2 1049-08-29
3 1050-07-01
-
并用
WITH
,INSERT OVERWRITE TABLE
-
先使用
with
,在最后的SQL前,加上insert overwrite table