乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      MySQL 多表關(guān)聯(lián)更新

       BigGuo 2010-03-03

      SET NAMES gb2312;

      CREATE TABLE `o` (
        `id` int(11) default NULL,
        `name` varchar(11) default NULL
      ) TYPE=MyISAM;

      insert into `o` values ('11','數(shù)據(jù)1');
      insert into `o` values ('22','數(shù)據(jù)2');
      insert into `o` values ('33','數(shù)據(jù)3');
      insert into `o` values ('44','數(shù)據(jù)4');


      CREATE TABLE `class1` (
        `id` int(11) default NULL,
        `name` varchar(11) default NULL
      ) TYPE=MyISAM;

      insert into `class1` values ('11','數(shù)據(jù)3');
      insert into `class1` values ('22','數(shù)據(jù)2');
      insert into `class1` values ('33','數(shù)據(jù)4');
      insert into `class1` values ('44','數(shù)據(jù)1');

      CREATE TABLE `class2` (
        `id` int(11) default NULL,
        `name` varchar(50) default NULL
      ) TYPE=MyISAM;

      insert into `class2` values ('11842542','子數(shù)據(jù)3');
      insert into `class2` values ('22543253','子數(shù)據(jù)2');
      insert into `class2` values ('33245235','子數(shù)據(jù)4');
      insert into `class2` values ('44543254','子數(shù)據(jù)1');


      SELECT *
      , CONCAT(o.id, RIGHT(B.id, LENGTH(CAST( B.id AS CHAR)) - 2)) value
      FROM class1 A, class2 B, o
      where A.id = Left(B.id, 2)
      and A.name = o.name;

      +------+-------+----------+---------+------+-------+----------+
      | id   | name  | id       | name    | id   | name  | value    |
      +------+-------+----------+---------+------+-------+----------+
      |   44 | 數(shù)據(jù)1  | 44543254 | 子數(shù)據(jù)1  |   11 | 數(shù)據(jù)1  | 11543254 |
      |   22 | 數(shù)據(jù)2  | 22543253 | 子數(shù)據(jù)2  |   22 | 數(shù)據(jù)2  | 22543253 |
      |   11 | 數(shù)據(jù)3  | 11842542 | 子數(shù)據(jù)3  |   33 | 數(shù)據(jù)3  | 33842542 |
      |   33 | 數(shù)據(jù)4  | 33245235 | 子數(shù)據(jù)4  |   44 | 數(shù)據(jù)4  | 44245235 |
      +------+-------+----------+---------+------+-------+----------+
      4 rows in set (0.00 sec)

      UPDATE
      class2
      LEFT JOIN class1  ON class1.id = LEFT(class2.id, 2)
      LEFT JOIN o ON class1.name = o.name
      SET class2.ID = CONCAT(o.id, RIGHT(class2.id, LENGTH(CAST(class2.id AS CHAR)) - 2)) ;

      Query OK, 3 rows affected (0.00 sec)
      Rows matched: 4  Changed: 3  Warnings: 0


      SELECT * FROM class2;

      +----------+---------+
      | id       | name    |
      +----------+---------+
      | 33842542 | 子數(shù)據(jù)3  |
      | 22543253 | 子數(shù)據(jù)2  |
      | 44245235 | 子數(shù)據(jù)4  |
      | 11543254 | 子數(shù)據(jù)1  |
      +----------+---------+
      4 rows in set (0.00 sec)

      DROP TABLE `o`;
      DROP TABLE `class1`;
      DROP TABLE `class2`;

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多