我正在尝试创建一个查询,该查询将从1列增加值并根据同一列的max int值更新自身
update
content
set
ord = (
select
tempOrd
from
(
select
max(ord) as 'tempOrd'
from
content
) as temp
) + 1
where section_id = 'news.article'
(编辑:通过查询删除冗余订单)
数据库中有67个条目,如果max(ord)
为10118
,则只会将所有条目的列更新为10119
。
我希望它能做10119, 10120, 10121, 10122, ...
答案 0 :(得分:1)
update content c
cross join (select max(ord) as max_ord from content) mx
cross join (select min(ord) as min_ord from content where section_id = 'news.article') mn
set c.ord = ord + 1 + mx.max_ord - mn.min_ord
where c.section_id = 'news.article'