将来自 select 的结果集和 dateadd 函数插入相同的 table

Inserting resultset from select and dateadd function into same table

我的 H2 数据库中有 "test" table,其中有一些时间戳。 我正在使用 'DATEADD' 函数将我的“_time”列转换为正常日期。

我希望将 select 查询的结果插入“_converted_time”

sql> select * from test;
| _TIME         | _CONVERTED_TIME
| 1468309423961 | null
| 1468309423962 | null
| 1468308812001 | null
| 1468308815972 | null
(4 rows, 10 ms)
sql> 
sql> 
sql> select DATEADD('SECOND', SUBSTRING(_time,1,10), DATE '1970-01-01') from test;
DATEADD('SECOND', SUBSTRING(EVENT_TIME, 1, 10), DATE '1970-01-01')
2016-07-12 07:43:43.0
2016-07-12 07:43:43.0
2016-07-12 07:33:32.0
2016-07-12 07:33:35.0

因此将以上结果添加到 _converted_time 后,它应该看起来像 ::

sql> select * from test;
| _TIME         | _CONVERTED_TIME
| 1468309423961 | 2016-07-12 07:43:43.0
| 1468309423962 | 2016-07-12 07:43:43.0
| 1468308812001 | 2016-07-12 07:33:32.0
| 1468308815972 | 2016-07-12 07:33:35.0
(4 rows, 10 ms)

提前致谢...

试试这个

update test
set CONVERTED_TIME = DATEADD('SECOND', SUBSTRING(_time,1,10), DATE '1970-01-01') 
WHERE CONVERTED_TIME IS NULL;