我有2个日期字段。一个完美运行(创建),第二个(交易时间)略有滞后。因此,我想使用我创建的日期,即unix时间,并使用from_unixtime将其设置为字段(事务时间)
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
答案 0 :(得分:2)
您不必使用子查询或JOIN来更新来自同一个表的数据的表。更简单,更快捷:
UPDATE transactions SET transactiontime=FROM_UNIXTIME(created)
WHERE transactiontime < '2011-01-01 00:00:00'
答案 1 :(得分:-2)
UPDATE transactions
SET transactiontime = created
WHERE id = 1
应该做得很完美