1, case when using, cleaning or the like content such as rating, using for example.
case
when new.comment_grade = '五星商户' then 50
when new.comment_grade = '准五星商户' then 45
when new.comment_grade = '四星商户' then 40
when new.comment_grade = '准四星商户' then 35
when new.comment_grade = '三星商户' then 30
when new.comment_grade = '准三星商户' then 25
when new.comment_grade = '二星商户' then 20
when new.comment_grade = '准二星商户' then 15
when new.comment_grade = '一星商户' then 10
when new.comment_grade = '准一星商户' then 5
when new.comment_grade = '该商户暂无星级' then 0
when new.comment_grade is NULL then old.comment_grade
else new.comment_grade
END as `new.comment_grade`,
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
2, replacing some of the contents of the string.
regexp_replace(new.avg_price, '-', '')
替换 avg_price 中的中划线。
- 1
- 2
3, the string segmentation function
split(a.tag_flag, '>')[1],
具体例子:
select split('a,b', ',')[0] ===> 结果 a
- 1
- 2
- 3
4, string concatenation function
SELECT concat('1', '2'); ====》 结果 12
SELECT concat('1', '2', '3'); ===> 结果 123
5, both ends of the string of blanks is removed
- 1
- 2
- 3
- 4
- 5
trim(a.city)
- 1
- 2
6, using left join or right join complement data
例如根据两张表,其中一张表格table2含有省份和城市的信息,
其中一张表table1只有城市信息,需要补全table1 中的省份信息,可以像如下做法:
select
a.name,
b.province,
a.city
from table1 a left join table2 b on a.city = b.city;
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
7, Other: Clear data that do not meet the conditions
可以使用等值判断来处理数据
清除一些不符合条件的数据。
INSERT OVERWRITE table ods.js_beauty_tmp
SELECT *
from ods.js_beauty_tmp
WHERE map_lat != ''
AND map_lng != ''
AND map_lat IS NOT NULL
AND map_lng IS NOT NULL
AND map_lat != 0
AND map_lng != 0
AND map_lat not like '-%'
AND map_lng not like '-%'
and city != '其他城市'
and city != '点评实验室';
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
</div>