[英]MySQL Update with Select statement from the same table
I have a table called time_table with the following columns 我有一个名为time_table的表,其中包含以下各列
--------------------------
time_table
--------------------------
col_name | type
id | int
user_time| datetime
This table has record in it. 该表中有记录。 When I updated the table to :
当我将表更新为:
--------------------------
time_table
--------------------------
col_name | type
id | int
user_time| datetime
utc_time | datetime
I want to Select all the user_time column, get its UTC equivalent and Update the utc_time column in one query. 我想选择所有user_time列,获取等效的UTC并在一个查询中更新utc_time列。
I tried this query but it didn't work. 我尝试了这个查询,但是没有用。
UPDATE time_table p1, (
SELECT id, CONVERT_TZ(user_time,'+00:00','+05:00') AS newtime
FROM time_table sp WHERE sp.id=p1.id) AS p2
SET p1.utc_time = p2.newtime
WHERE p1.id = p2.id
I know there is something wrong with my query but I don't know what's wrong with it. 我知道查询有问题,但是我不知道这有什么问题。 Any suggestions?
有什么建议么? It would be a great help.
这将是一个很大的帮助。
You don't need to join 你不需要参加
UPDATE time_table
SET utc_time = CONVERT_TZ(user_time, '+00:00','+05:00')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.