希望有人可以用一条sql语句完成。
update report,manageTerm  set reportTo=termId where ???

解决方案 »

  1.   

    呵呵 只能帮忙顶下 
    关注ing
      

  2.   

    另外这是  helloyou0(你好!)  在4.1.10上的测试情况。
    我想请问,有谁能说说在4.0.12上可以不么?有什么不支持的么,还是怎么样?运行前数据:
    ---------------------------------------------------------------
    -- phpMyAdmin SQL Dump
    -- version 2.6.1
    -- http://www.phpmyadmin.net
    -- 
    -- Host: localhost
    -- Generation Time: Apr 17, 2005 at 03:11 AM
    -- Server version: 4.1.10
    -- PHP Version: 4.3.9
    -- 
    -- Database: `test`
    -- -- ---------------------------------------------------------- 
    -- Table structure for table `m`
    -- DROP TABLE IF EXISTS m;
    CREATE TABLE m (
      termId int(11) NOT NULL auto_increment,
      termName varchar(50) NOT NULL default '',
      categoryId int(11) NOT NULL default '0',
      PRIMARY KEY  (termId)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=104 ;-- 
    -- Dumping data for table `m`
    -- INSERT INTO m VALUES (101, '1¨¹¨¤¨ª¨ª??¨®1', 1);
    INSERT INTO m VALUES (102, '1¨¹¨¤¨ª¨ª??¨®2', 2);
    INSERT INTO m VALUES (103, '1¨¹¨¤¨ª¨ª??¨®3', 3);-- ---------------------------------------------------------- 
    -- Table structure for table `r`
    -- DROP TABLE IF EXISTS r;
    CREATE TABLE r (
      id int(11) NOT NULL auto_increment,
      categoryId int(11) NOT NULL default '0',
      adminId int(11) NOT NULL default '0',
      PRIMARY KEY  (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;-- 
    -- Dumping data for table `r`
    -- INSERT INTO r VALUES (1, 1, 1);
    INSERT INTO r VALUES (2, 2, 1);
    INSERT INTO r VALUES (3, 3, 1);
    INSERT INTO r VALUES (4, 2, 2);
    INSERT INTO r VALUES (5, 3, 2);
    INSERT INTO r VALUES (6, 3, 3);-- ---------------------------------------------------------- 
    -- Table structure for table `report`
    -- DROP TABLE IF EXISTS report;
    CREATE TABLE report (
      id int(11) NOT NULL auto_increment,
      title varchar(50) NOT NULL default '',
      content text,
      createTime datetime default NULL,
      reportTo varchar(20) default NULL,
      PRIMARY KEY  (id)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;-- 
    -- Dumping data for table `report`
    -- INSERT INTO report VALUES (1, '??1', '????1', '2005-04-16 15:00:00', '1');
    INSERT INTO report VALUES (2, '??2', '????2', '2005-04-16 15:00:00', '1');
    INSERT INTO report VALUES (3, '??3', '????3', '2005-04-16 15:00:00', '2');
    INSERT INTO report VALUES (4, '??4', '????4', '2005-04-16 15:00:00', '3');
    INSERT INTO report VALUES (5, '??5', '????5', '2005-04-16 15:00:00', '1');
    INSERT INTO report VALUES (6, '??6', '????6', '2005-04-16 15:00:00', '2');
    =========================================mysql中运行画面拷贝:
    mysql> use test;
    Database changed
    mysql> select * from report;
    +----+-------+---------+---------------------+----------+
    | id | title | content | createTime          | reportTo |
    +----+-------+---------+---------------------+----------+
    |  1 | ??1   | ????1   | 2005-04-16 15:00:00 | 1        |
    |  2 | ??2   | ????2   | 2005-04-16 15:00:00 | 1        |
    |  3 | ??3   | ????3   | 2005-04-16 15:00:00 | 2        |
    |  4 | ??4   | ????4   | 2005-04-16 15:00:00 | 3        |
    |  5 | ??5   | ????5   | 2005-04-16 15:00:00 | 1        |
    |  6 | ??6   | ????6   | 2005-04-16 15:00:00 | 2        |
    +----+-------+---------+---------------------+----------+
    6 rows in set (0.00 sec)mysql> update report set reportTo=(
        -> select t from
        -> (
        -> select adminId a,termId t from r,m
        -> where r.categoryId=m.categoryId group by adminId
        -> ) x
        -> where x.a=report.reportTo);
    Query OK, 6 rows affected (0.03 sec)
    Rows matched: 6  Changed: 6  Warnings: 0
      

  3.   

    已经确定是版本问题
    4.1 支持PreparedStatement (预处理语句,一种临时存储过程)估计4.0的就只能用2条语句了,
    1 创建临时表,存储对应关系,
    2 update tablea as a,talbeb as b set a.xxx = b.xxx where a.yyy=b.yyy;
    明天结贴,大家来接分:)