实习第五天10.12
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的表按照老字段添加一个新字段()
1 | ALTER TABLE testalter_tbl ADD i int ;<br><br>注意如果想新加一个 varchar 类型的字段必须给 varchar (20)限定长度 |
将字符串 abc 中的字符 a 替换为字符 x:
1 | 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 结合使用
1 2 3 4 | 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语句
1 2 3 4 5 6 7 | 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' <br> and street_id is not null ; |
③case when的使用方法
1 2 3 4 5 6 7 8 9 10 11 | 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
1 2 3 4 5 6 | 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
1 2 3 4 5 6 | 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; |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Java 中堆内存和栈内存上的数据分布和特点
· 开发中对象命名的一点思考
· .NET Core内存结构体系(Windows环境)底层原理浅谈
· C# 深度学习:对抗生成网络(GAN)训练头像生成模型
· .NET 适配 HarmonyOS 进展
· DeepSeek+PageAssist实现本地大模型联网
· 手把手教你更优雅的享受 DeepSeek
· 腾讯元宝接入 DeepSeek R1 模型,支持深度思考 + 联网搜索,好用不卡机!
· 从 14 秒到 1 秒:MySQL DDL 性能优化实战
· AI工具推荐:领先的开源 AI 代码助手——Continue