表1
序号 姓名 入职时间 离职时间  id
 1    f      2000     2010   156
 2    d      1999     null   null
 3    j      1998     null   null序号为主键(自增长)update 表1 set id='123' 离职时间=SYSDATE() where id=null 并且 序号为最小的一个红色部分为where的条件,实现找到一个id为空的唯一的一行,最大或最小无所谓

解决方案 »

  1.   


    update 表1 set id='123' 离职时间=SYSDATE() where 序号=(select min(序号) from 表1 where )
      

  2.   

    update 表1 set id='123' 离职时间=SYSDATE() where 序号=(select min(序号) from 表1 where id=null  )
      

  3.   

    报1093错误 不能子查询
    ERROR 1093 You can't specify target table 'forum_members' for update in FROM clause
      

  4.   

    update 表1 a inner join (select min(序号) as id from 表1 where id=null  ) b  on a.序号=b.id
    set id='123',离职时间=SYSDATE() 
      

  5.   

    /*
    MySQL Data Transfer
    Source Host: localhost
    Source Database: zlink
    Target Host: localhost
    Target Database: zlink
    Date: 2010-11-23 23:29:32
    */SET FOREIGN_KEY_CHECKS=0;
    -- ----------------------------
    -- Table structure for ctcm_en_didmanage
    -- ----------------------------
    CREATE TABLE `ctcm_en_didmanage` (
      `DIDID` int(50) NOT NULL AUTO_INCREMENT,
      `DIDNUMBER` varchar(100) NOT NULL,
      `DIDINTIME` date NOT NULL,
      `DIDSTATE` varchar(100) NOT NULL DEFAULT '0',
      `DIDOUTTIME` datetime DEFAULT NULL,
      `ID` varchar(100) DEFAULT NULL,
      PRIMARY KEY (`DIDID`)
    ) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;-- ----------------------------
    -- Records 
    -- ----------------------------
    INSERT INTO `ctcm_en_didmanage` VALUES ('1', '1212121', '2010-11-23', '0', null, '2088888888');
    INSERT INTO `ctcm_en_didmanage` VALUES ('2', '3333344555', '2010-11-08', '0', null, '2010000003');
    INSERT INTO `ctcm_en_didmanage` VALUES ('3', '658809', '2010-11-23', '1', '2010-11-23 23:09:53', '2010000004');
    INSERT INTO `ctcm_en_didmanage` VALUES ('4', '5787890', '2010-11-23', '0', null, null);
    INSERT INTO `ctcm_en_didmanage` VALUES ('5', '43434343', '2010-11-23', '0', null, null);
    update ctcm_en_didmanage a inner join (select min(DIDID) as im from ctcm_en_didmanage   where ID=null) b on a.DIDID=b.im set ID = '2010000004', DIDSTATE = '1', DIDOUTTIME = SYSDATE() 
    表及sql语句如上,能够执行,但没有影响任何行
    影响的数据栏: 0
    时间: 0.000ms
      

  6.   

    update ctcm_en_didmanage a inner join (select min(DIDID) as im from ctcm_en_didmanage   where ID is null) b on a.DIDID=b.im set ID = '2010000004', DIDSTATE = '1', DIDOUTTIME = SYSDATE()  
      

  7.   

    update ctcm_en_didmanage
    set DIDOUTTIME=SYSDATE()
    where id is null order by DIDID   limit 1