团队作业-冲刺二(4)

利用python爬虫后的数据处理

1.1、设置变量 set @变量名=值

set @address='中国-山东省-聊城市-莘县';
select @address

1.2 、length()函数 char_length()函数区别

select length('a')
,char_length('a')
,length('中')
,char_length('中')

1.3、 replace() 函数 和length()函数组合

set @address='中国-山东省-聊城市-莘县';
select @address
,replace(@address,'-','') as address_1
,length(@address) as len_add1
,length(replace(@address,'-','')) as len_add2
,length(@address)-length(replace(@address,'-','')) as _count

etl清洗字段时候有明显分割符的如何确定新的数据表增加几个分割出的字段

计算出com_industry中最多有几个 - 符 以便确定增加几个字段 最大值+1 为可以拆分成的字段数 此表为3 因此可以拆分出4个行业字段 也就是4个行业等级

select max(length(com_industry)-length(replace(com_industry,'-',''))) as _max_count
from etl1_socom_data

1.4、设置变量 substring_index()字符串截取函数用法

set @address='中国-山东省-聊城市-莘县';
select
substring_index(@address,'-',1) as china,
substring_index(substring_index(@address,'-',2),'-',-1) as province,
substring_index(substring_index(@address,'-',3),'-',-1) as city,
substring_index(@address,'-',-1) as district

1.5、条件判断函数 case when

case when then when then else 值 end as 字段名

select case when 89>101 then '大于' else '小于' end as betl1_socom_data
posted @ 2023-05-11 21:41  旺旺大菠萝  阅读(10)  评论(0编辑  收藏  举报