数据在mysql中有几百万条,现在每个id下面的类别信息都不完整,需要补齐类别并置为0,需要怎么弄呢?
假设下表B,是这样的(–只是为了格式):
id class_id class info
1 ----- 1 ------ 明星 。。。。。
2 --------------- 军事 。。。。。
3 ------ 3------- ---------- 。。。。。
4 ---------------- ---------- 高考分数
类别表C
class_id class
1 ---- 明星
2 ----- 军事
3 -----体育
4 -----高考
比如上面这样的一个情况,你需要补齐类别信息,class_id或者class信息。
一、首先,使用select统计缺失情况。
统计class_id缺失的有多少:select count(*) from b where class_id is null or class_id = ’ ’ and class is not null;
统计class缺失的有多少:select count(*) from b where class is null or class_id = ’ ’ and class_id is not null;
在正式更新之前,建议,先备份一次,或者创建一张复制表。
create table b_test select * from b; 数据太大,就换一种方式:
create table b_test select * from b where 1=2; 这样就只创建一张表结构,没有数据,
装载数据