如何通过选择mysql进行更新

如何通过选择mysql进行更新,mysql,select,sql-update,Mysql,Select,Sql Update,我有两个日期字段。一个完美地工作,第二个事务时间稍微滞后。因此,我想使用我创建的日期,即unix时间,并通过使用from_unixtime将其转换为字段transactiontime transactionsid created transactiontime 1 1362140510 2013-06-06 16:55:21 2 1362501952

我有两个日期字段。一个完美地工作,第二个事务时间稍微滞后。因此,我想使用我创建的日期,即unix时间,并通过使用from_unixtime将其转换为字段transactiontime

transactionsid         created            transactiontime
1                      1362140510         2013-06-06 16:55:21
2                      1362501952         1980-02-01 13:25:52
3                      1362502022         1980-02-02 14:20:10    
3                      1364224671         0
and so on, and so on
我就是这样尝试的。但这行不通,因为它不能让我定义t3,为什么会发生这种情况?还有更简单的方法吗

UPDATE transactions as t1
set t1.transactiontime = 
(
select FROM_UNIXTIME(t2.created) 
from transactions as t2 
where t2.transactiontime < '2011-01-01 00:00:00'
) as t3
where t1.transactionid = t3.transactionid

您不必使用子查询或联接来使用来自同一个表的数据更新表。更简单、更快:

UPDATE transactions SET transactiontime=FROM_UNIXTIME(created) 
WHERE transactiontime < '2011-01-01 00:00:00'

应该工作正常

尝试将事务更新为t1 set t1.transactiontime=FROM_unixtime2.created,其中t2.transactiontime<'2011-01-01 00:00:00'不起作用吗?UPDATE transactions SET transactiontime=来自创建transactiontime的_unixtime,其中transactiontime<'2011-01-01 00:00:00'Arh,谢谢@Maris。我会在8分钟内接受你的回答:是的,我的坏朋友忘记了UNIXTIME部分
UPDATE transactions 
SET transactiontime = created 
WHERE id = 1