有一个名为vouchers的表,我需要对表的优先级进行排序,序列号从1开始。我还可以更改优先级,例如,我将优先级从5更改为1,因此序列从1递增到4 ...(即)5变成1,1变成2,2变成3,依此类推。同样,当优先级5变为10时,6变为5,7变为6,依此类推。
而且凭证还具有到期日期,因此,当用户要求按顺序使用凭证时,应省略过期凭证的现有订单号,并应更新新的顺序。
我不应该更改现有的优先级配置。
我尝试了以下查询,但工作不正常。
UPDATE deals a
LEFT JOIN
(SELECT id, order_no, @i:=@i+1 AS sequence from deals, (SELECT @i:=0) var WHERE id >= 1 AND status = 1 AND promotion_start_at <= '${today}' AND promotion_end_at > '${today}' order by order_no limit 0,10) b
ON b.id = a.id
SET a.order_no = b.sequence
WHERE a.id = b.id
status column 1 - active, 2 - inactive, 3 - deleted
id status exipiring_date sequence
1 1 10/12/2019 1
2 1 10/12/2019 2
3 1 10/12/2019 3
4 1 10/12/2019 4
5 1 10/12/2019 5
When i change sequence from 5 to 1, it should become like this
id status exipiring_date sequence
1 1 10/12/2019 2
2 1 10/12/2019 3
3 1 10/12/2019 4
4 1 10/12/2019 5
5 1 10/12/2019 1
for example when the id-2 is expired
id status exipiring_date sequence
1 1 10/12/2019 2
2 1 10/12/2019 null(expired)
3 1 10/12/2019 3
4 1 10/12/2019 4
5 1 10/12/2019 1(Here the old config doesn't changed)
我希望在某些交易到期后更改优先级并管理优先级。
一些约束是: