SELECT ONE ROW that has a priority value = 1 otherwise select the lowest queue id

问题描述 投票:0回答:1

我正在制作一个 FCFS 但使用优先级算法。不管队列ID如何,首先选择优先级的最佳sql命令是什么。如果队列中没有优先级,则选择队列中的第一个或最小的队列 ID。谢谢

示例表名 cashier_queue_list

在表中,对于这种情况,将选择 3 号队列,因为它的优先级值为 1。然后在从表中删除该队列后,它可能应该在下一次运行后选择 5,下一个 7,然后现在没有优先级,队列1。请帮忙谢谢。

sql queue sql-order-by priority-queue
1个回答
0
投票

你只是想要

order by
吗?

select *
from mytable
order by 
    priority desc, -- priority 1 comes first
    queue_id       -- then sort queues by ascending order (least id comes first)
© www.soinside.com 2019 - 2024. All rights reserved.