首页 新闻 赞助 找找看

SQL 删除后的字段值修改问题

0
悬赏园豆:10 [已解决问题] 解决于 2015-12-11 11:47

比如,我有这样一张表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语句表达了?

彳亍者的主页 彳亍者 | 初学一级 | 园豆:108
提问于:2015-12-11 10:35
< >
分享
最佳答案
0

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

收获园豆:10
wang8662350 | 菜鸟二级 |园豆:214 | 2015-12-11 10:57

谢谢!我现在有点纠结,是这样写还是用触发器,能给点建议么?

彳亍者 | 园豆:108 (初学一级) | 2015-12-11 11:33
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册