I have 3 tables. I'm inserting data from t1 into t2 and t3. I would like to only insert the data from t1 that is newer than the newest data already in t2.
This is my current select statement:
from (select *, concat(column1, '|', column2) as id from t1
where column1 = "value1") t
insert into table t2
select
column3,
id
insert into t3
select
column4
id
t1, t2 and t3 also contain a column "ttime", of type timestamp. I would like to modify my insert statement above to only insert data
where t1.ttime > max(t2.ttime)
How can I do this?
答案 0 :(得分:0)
with subreq as (select max(time) from t2)
insert into t2 select * from t1 where t1.time>subreq.time
只需进行查询with
,然后您就可以引用其中的任何列以供进一步操作