比如,我有这样一张表table(如下图),
要进行这样两个SQL语句,
delete from table where ID=2 和 update table set listNo=listNo-1 where listNo>(selsect listNo from table where ID=2) and fkID=1
怎么用一个SQL语句表达了?
merge into table as target
using(select Id from table) as source on target.id=source.id
when matched then update set target.listNo=target.listNo-1 where target.listNo>(selsect listNo from table where ID=2) and target.fkID=1
delete where ID=2
谢谢!我现在有点纠结,是这样写还是用触发器,能给点建议么?