简体   繁体   English

MySQL问题:将查询结果添加到同一表的列中

[英]MySQL issue : adding the result of a query to a column in the same table

SELECT CONCAT(
  from_unixtime(lastSaleTime/1000, '%Y-%d-%m %h:%i:%s.'),
  CAST(EXTRACT(MICROSECOND FROM from_unixtime(lastSaleTime/1000))/1000 
  AS SIGNED)
) FROM IEX_Tick;

This code returns a column of values, and I want to add all that data to a new column that I created. 这段代码返回一列值,我想将所有数据添加到我创建的新列中。 This was suggested last time: 上次建议这样做:

UPDATE IEX_Tick SET SomeColumn = (
   SELECT CONCAT(
       from_unixtime(lastSaleTime/1000, '%Y-%d-%m %h:%i:%s.'),
       CAST(EXTRACT(MICROSECOND FROM from_unixtime(lastSaleTime/1000))/1000 AS SIGNED)
   ) FROM IEX_Tick;
)

However I get the error "You can't specify target table 'IEX_Tick' for update in FROM clause. I looked that up and we have tried some of the workarounds, for example: 但是我收到错误消息“您无法在FROM子句中指定目标表'IEX_Tick'进行更新。我查了一下,我们尝试了一些解决方法,例如:

UPDATE IEX_Tick SET SomeColumn = (
   SELECT CONCAT(
       from_unixtime(lastSaleTime/1000, '%Y-%d-%m %h:%i:%s.'),
       CAST(EXTRACT(MICROSECOND FROM from_unixtime(lastSaleTime/1000))/1000 AS SIGNED)
   ) FROM (Select * from IEX_Tick) as RRR;
)

But it still doesn't work 但这仍然行不通

Simply eschew the subquery: 只需避开子查询:

UPDATE IEX_Tick
    SET SomeColumn = CONCAT(from_unixtime(lastSaleTime/1000, '%Y-%d-%m %h:%i:%s.'),
                             CAST(EXTRACT(MICROSECOND FROM from_unixtime(lastSaleTime/1000))/1000 AS SIGNED)
                            );

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

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