update tb_category set sortrank=sortrank-2 where category_id like '00'
update tb_category set sortrank=sortrank+2 where category_id like '11';
...全文
1019打赏收藏
请教SQL语句写法
要对同一个表进行两次修改,两次修改都成功才能最后成功(也就是要具备事务的功能),但是如果在这里用事务的话,那么就执行不了,会被锁定,所以不知道这种情况应该如何处理好,请各位大大们指教! 假设要执行的SQL如下: update tb_category set sortrank=sortrank-2 where category_id like '00' update tb_category set sortrank=sortrank+2 where category_id like '11';
[Quote=引用 1 楼 feixianxxx 的回复:]
SQL code
update tb_category
set sortrank=case when category_id like '00' then sortrank-2
when category_id like '11' then sortrank+2
else sortrank;
写成一句……
[/Quote]
这样写报错了,#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
引用 1 楼 feixianxxx 的回复:
SQL code
update tb_category
set sortrank=case when category_id like '00' then sortrank-2
when category_id like '11' then sortrank+2
else sortrank;