id name datetime
1 a 2010-05-13 10:15:00
2 b 2010-05-14 09:10:00
3 d 2010-05-14 10:10:00如何将距离目前最近的那个记录的name 更新为“x”呢谢谢咯 啊 呵呵
1 a 2010-05-13 10:15:00
2 b 2010-05-14 09:10:00
3 d 2010-05-14 10:10:00如何将距离目前最近的那个记录的name 更新为“x”呢谢谢咯 啊 呵呵
解决方案 »
- java中访问权限的小问题
- 内部匿名类使用外部成员变量,外部成员变量要定义为final?
- JComboBox异常
- 为什么在服务端关闭了相应的连接端口,但其还能调用getInetAddress()
- 找高手请教ResultSet的rs对象该在何处rs.close()
- ping和Date
- Java中如何实现“条件编译”?
- MyBatis的XML属性表应该怎样配置?
- ***有参加过大连雅奇软件开发高级研修班的吗?希望大家给点建议...***
- 关于Applet请高手给点建议,跟帖有分!
- 手头有个服务器项目请看看想知道是不是找开源代码改的
- 使用SSLSocket发送接收utf-8编码的汉字为什么是乱码??
update table_name a set name='x' where exists (
select 1 from (
select max(datetime) from table_name
) b where b.datetime=a.datetime
);
错误提示就是说,不能先select出同一表中的某些值,再update这个表(在同一语句中) 思路,create table_name as select max(datetime) as datetime from table_name
然后update table_name set name='x' where datetime in 上面那个表;
然后drop那个表试试
where (sysdate-datetime) = (
select min(sysdate-datetime) from
表 )
oracle中测试成功,mysql中现在的时间是不是sysdate我就不大清楚了
mysql> select * from tbl;
+------+------+---------------------+
| id | name | ttime |
+------+------+---------------------+
| 1 | a | 2010-05-14 11:08:00 |
| 2 | b | 2010-05-14 11:08:43 |
| 3 | d | 2010-05-14 11:08:47 |
+------+------+---------------------+
3 rows in set (0.00 sec)mysql> update tbl set name='x' where not exists(select 1 from tbl b where b.ttime < tbl.ttime);
ERROR 1093 (HY000): You can't specify target table 'tbl' for update in FROM clause