卖逼视频免费看片|狼人就干网中文字慕|成人av影院导航|人妻少妇精品无码专区二区妖婧|亚洲丝袜视频玖玖|一区二区免费中文|日本高清无码一区|国产91无码小说|国产黄片子视频91sese日韩|免费高清无码成人网站入口

mysql補齊缺省數(shù)據(jù)?

網(wǎng)友解答: 你給的信息太少,我給你舉例吧,假設(shè)下表B,是這樣的(--只是為了格式):id class_id class info1 ----- 1 --

網(wǎng)友解答:

你給的信息太少,我給你舉例吧,假設(shè)下表B,是這樣的(--只是為了格式):

id class_id class info

1 ----- 1 ------ 明星 。。。。。

2 --------------- 軍事 。。。。。

3 ------ 3------- ---------- 。。。。。

4 ---------------- ---------- 高考分?jǐn)?shù)

類別表C

class_id class

1 ---- 明星

2 ----- 軍事

3 -----體育

4 -----高考

比如上面這樣的一個情況,你需要補齊類別信息,class_id或者class信息。

一、首先,使用select統(tǒng)計缺失情況。

統(tǒng)計class_id缺失的有多少:select count(*) from b where class_id is null or class_id = ' ' and class is not null;

統(tǒng)計class缺失的有多少:select count(*) from b where class is null or class_id = ' ' and class_id is not null;

在正式更新之前,建議,先備份一次,或者創(chuàng)建一張復(fù)制表。

create table b_test select * from b; 數(shù)據(jù)太大,就換一種方式:

create table b_test select * from b where 1=2; 這樣就只創(chuàng)建一張表結(jié)構(gòu),沒有數(shù)據(jù),

裝載數(shù)據(jù):

insert into b_test select * from b where id <20000;

依次類推,直到裝載完畢。千萬不要直接在原表上直接更新。

如果統(tǒng)計的數(shù)量較多,例如超過10w,請分批執(zhí)行。

補齊class:update b_test,c set b_test.class=c.class where b_test.class_id=c.class_id and b_test.id in (select id from b_test where class is null or class_id = ' ' and class_id is not null limit 0,20000);

每次只會2w行的更新,多次執(zhí)行上面SQL語句,對應(yīng)修改 b_test.id in (select id from b_test where class is null or class_id = ' ' and class_id is not null limit 20000,40000);

依次類推。

補齊class_id:其實也一樣:

update b_test,c set b_test.class_id=c.class_id where b_test.class=c.class and b_test.id in (select id from b_test where class is null or class_id = ' ' and slass_id is not null limit 0,20000 ;

使用統(tǒng)計的SQL,確認(rèn)一次,是否還有沒有修改到的。

最后剩下,class和class_id都沒有的,

你可能只有手動處理了。或者

update b_test set b_test.id=4,b_test.class='高考' where info like '%高考%';

希望能幫助你解決問題。有任何問題,歡迎私信我。

網(wǎng)友解答:

直接使用語句設(shè)置字段值為0就可以了 update 表名 set field = 0

標(biāo)簽: