简体   繁体   English

通过使用INSERT…SELECT将数据类型从unix时间戳更改为mysql datetime。

[英]Change datatype from unix timestamp to mysql datetime by using INSERT … SELECT

I have to fix a table where date and time are stored as unix timestamps. 我必须修复一个将日期和时间存储为unix时间戳的表。 I want to convert the current format into the mysql datetime type while preserving the original columns for the moment. 我想将当前格式转换为mysql datetime类型,同时保留当前的原始列。 (working on a running system, a bit like open heart surgery). (在运行的系统上工作,有点像心脏直视手术)。

I have made a copy of the current table and want to a FROM_UNIXTIMESTAMP to inser the values into the original table into the matching rows. 我已经制作了当前表的副本,并希望复制到FROM_UNIXTIMESTAMP以将值插入原始表中的匹配行中。 I might be on the right track with my statement but I can't get it to work. 我的陈述可能走在正确的道路上,但我无法使它发挥作用。

INSERT INTO signup (add_time) SELECT FROM_UNIXTIME(addtime) FROM signup_backup WHERE signup.UID = signup_backup.UID;

This is my current approach but I get unknown column and I know why but I can't figure out how to fix the syntax of the statement. 这是我目前的方法,但是我不知道该列,但我知道为什么,但是我不知道如何修复该语句的语法。

Why do you use INSERT? 为什么要使用INSERT? I guess you should use UPDATE: 我猜您应该使用UPDATE:

UPDATE signup LEFT JOIN signup_backup ON signup.UID= signup_backup.UID
SET signup.add_time = FROM_UNIXTIME(signup_backup.addtime) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM