You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
-- ALTER TABLE t_base_person CONVERT TO CHARACTER SET gbk COLLATE gbk_chinese_ci;
|
|
|
|
|
|
|
|
|
|
数据清洗分两种情况
|
|
|
|
|
(1)、校验上报的数据字段,是不是在范围内,校验即可,不扩展其它字段
|
|
|
|
|
比如:用户上报了一条学生作业得分数据,但学生的ID,不在学生表的ID范围内
|
|
|
|
|
|
|
|
|
|
(2)、校验上报的数据字段,是不是在范围内,除校验外,需要扩展其它字段
|
|
|
|
|
比如:用户上报了一条学生作业得分数据,需要在检查zy_id是否合法的前提下,扩展出zy_name字段
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- 下面分别进行讨论:
|
|
|
|
|
|
|
|
|
|
-- 增加 check_flag字段
|
|
|
|
|
-- ALTER TABLE `huanghai`.`t_zy_score` ADD COLUMN `check_flag` smallint NOT NULL DEFAULT 0 COMMENT '0:待校验,1:校验成功,-1:校验失败';
|
|
|
|
|
|
|
|
|
|
-- 添加check_flag字段索引
|
|
|
|
|
-- ALTER TABLE `huanghai`.`t_zy_score` ADD INDEX(`check_flag`);
|
|
|
|
|
|
|
|
|
|
-- 还原现场
|
|
|
|
|
update t_zy_score set check_flag=0,zy_name=null;
|
|
|
|
|
|
|
|
|
|
-- 第一种情况对不上的修改为-1
|
|
|
|
|
update t_zy_score as t1 left join t_base_person as t2 on t1.person_id=t2.person_id set t1.check_flag=-1 where t2.person_id is null limit 100;
|
|
|
|
|
|
|
|
|
|
-- 第二种情况对不上的,保留扩展字段为空
|
|
|
|
|
update t_zy_score as t1 left join t_zy_main as t2 on t1.zy_id=t2.zy_id set t1.zy_name=t2.zy_name where t1.zy_name is null limit 100;
|
|
|
|
|
update t_zy_score as t1 set t1.check_flag=-1 where t1.zy_name is null limit 100;
|
|
|
|
|
|
|
|
|
|
-- 最终修改正确标识
|
|
|
|
|
update t_zy_score as t1 set check_flag=1 where check_flag=0 limit 100;
|
|
|
|
|
|
|
|
|
|
select * from t_zy_score
|