merge 可以实现你的功能,假设你products为T1表,等待处理的记录在T2表 merge into t1 using t2 on(t1.pid=t2.pid) when matched then update set t1.min=(case when t1.price>t2.price then t1.min else t1.price end) when not matched then insert values(t2.id,t2.pid,t2.price,t2.promotion,t2.min); PS:如果ID为自增的,可以将values中的T2.id换成的自增序列
merge into t1 using t2 on(t1.pid=t2.pid)
when matched then
update set t1.min=(case when t1.price>t2.price then t1.min else t1.price end)
when not matched then
insert values(t2.id,t2.pid,t2.price,t2.promotion,t2.min);
PS:如果ID为自增的,可以将values中的T2.id换成的自增序列