亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

在MySQL中來平移對應的行

標簽:
MySQL


以前写的,笨办法,不知道大家有什么好的办法没有?

表结构:

/*DDL Information For - t_girl.yld1*/

-------------------------------------

Table   Create Table                                             

------  ---------------------------------------------------------

yld1    CREATE TABLE `yld1` (                                    

          `id` int(11) default NULL,                             

          `uid` int(11) default NULL                             

        ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC

初始数据:

query result(4 records)

id  uid

(NULL)  6

(NULL)  5

2   (NULL)

1   (NULL)

执行过程:

create table yld2 select * from yld1

delete from yld1 where id is null;

delete from yld2 where id is not null;

alter table yld1 add autoid int not null AUTO_INCREMENT primary key;

alter table yld2 add autoid int not null AUTO_INCREMENT primary key;

update yld1 as a,yld2 as b set a.uid = b.uid where a.autoid = b.autoid;

alter table yld1 drop autoid;

drop table yld2;

 最终结果:

query result(2 records)

id  uid

2   6

1   5

©著作权归作者所有:来自51CTO博客作者david_yeung的原创作品,如需转载,请注明出处,否则将追究法律责任

职场MySQL数据库SQL语句与特殊技巧


點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消