1.mysql连接失败:Can't connect to MySQL server on xxx (10061)
参考:https://jingyan.baidu.com/article/a681b0de5ac1dc3b1943467d.html
解决方法:1).快捷键“win+r”打开【运行】,然后在文本框输入“services.msc”后点击【确定】或回车,就能打开服务窗口
2)在服务窗口找到mysql并运行:
3)如果服务中没有mysql则安装:cmd中输入mysqld -install
2.阿里云的max compute与MySQL的区别:
https://help.aliyun.com/document_detail/50985.html?spm=a2c4g.11186623.2.11.691d17d0vvY3WM
3.给sql的表按照老字段添加一个新字段()
ALTER TABLE testalter_tbl ADD i int;
注意如果想新加一个varchar类型的字段必须给varchar(20)限定长度
将字符串 abc 中的字符 a 替换为字符 x:
SELECT REPLACE('abc','a','x')
注意:1.abc可以放字段名 2.replace可以嵌套使用起到多次修改的作用
CONCAT(s1,s2,s3)返回s1+s2+s3的结果。
处理字典表更正街道id整体思路:代码见下边缓存
①给region表加一列模糊数据
②构建同结构的新表
④向新表里插入数据数据源为base表和region表
1..给大表加一列特殊模糊名字的操作
①构建同结构的新表
②给新表新加一列
③向新表里插入数据
其中特殊模糊名字的那列操作方法:用嵌套replace删除多余的内容。
两头加%去掉居委会、街道本级、社区、村委会
concat('%',replace(replace(replace(replace(字段名,'居委会',''),'社区',''),'街道本级',''),'村委会',''),'%')
两头加%去掉街道、乡、镇:concat('%', replace(replace(replace(字段名,'街道' ,'' ),'乡' ,'' ),'镇' ,'' ) ,'%')
2.创建新表(只要结构)
3.向新表插入数据
注意排除掉无意义的测试数据
插入数据实现逻辑:①矫正二级id生成中间表temp_tb1②根据temp_tb2矫正3级id。
sql缓存文件
①insert into 和select 结合使用
insert into newtb (district,districtid,town,townid,village,villageid) select infotb.district,infotb.districtid,infotb.town,infotb.townid,infotb.village,dictionary.villageid from infotb,dictionary where infotb.village like dictionary.village and infotb.town like dictionary.town and infotb.districtid like dictionary.districtid;
②去除测试数据的sql语句
select count(*) from to_stat_info where event_desc not like '%测试%' and lower(event_desc) not like '%test%' and lower(event_desc) not like '%teat%' and event_src_name not like '%8890%' and event_src_id in(1,5,100,1002) and create_time >='2019-08-25'
and street_id is not null;
③case when的使用方法
case when update student set sname = case when xuehao='20162219' then 'xingyu' when xuehao='20162218' then 'tianyang' when xuehao='20162220' then 'xiaozhou' else sname end; insert into newtb (district,districtid,town,townid,village,villageid) select infotb.district,infotb.districtid,infotb.town,infotb.townid,infotb.village, concat('%',replace(replace(dictionary.villageid,'1',''),'2',''),'%') from infotb,dictionary where infotb.village like dictionary.village and infotb.town like dictionary.town and infotb.districtid like dictionary.districtid;
④处理字典表更正街道id
#给base_region添加一个re_name模糊列,新建到表new_base
create table if not exists new_base(like base_region); alter table new_base add re_name varchar(20); insert into new_base (id,type,district_id,district_name,street_id,street_name,community_id,community_name,street_count,countryside_count,town_count,jwh_count,cwh_count,re_name) select id,type,district_id,district_name,street_id,street_name,community_id,community_name,street_count,countryside_count,town_count,jwh_count,cwh_count,concat('%', replace(replace(replace(street_name,'街道',''),'乡',''),'镇',''),'%')
from base_region;
#通过查tc_region将new_base表中的street_id更正,新建到表new_base2
create table if not exists new_base2(like new_base); insert into new_base2 (id,type,district_id,district_name,street_id,street_name,community_id,community_name,street_count,countryside_count,town_count,jwh_count,cwh_count,re_name) select new_base.id,new_base.type,new_base.district_id,new_base.district_name,tc_region.region_id,new_base.street_name,new_base.community_id,new_base.community_name,new_base.street_count,new_base.countryside_count,new_base.town_count,new_base.jwh_count,new_base.cwh_count,new_base.re_name from new_base,tc_region where tc_region. region_name like new_base.re_name and region_type=3;