I have a table called months
- this contains all 12 months of the calendar, the IDs correspond to the month number.
我将运行查询以从该表中检索2或3个连续的月,例如
- 四月和五月
- 六月七月八月
- 十二月和一月
但是,我想确保每当12月是一月并被检索时,它将按该顺序而不是一月-12月来检索它们。这是我尝试过的:
SELECT * FROM `months`
WHERE id IN(12, 1)
ORDER BY
FIELD(id, 12, 1)
This works for December & January, but now when I try to retrieve January & February it does those in the wrong order, i.e "February - January" - I'm guessing because we specified 1
in the ORDER BY
as the last value.
有人知道实现此目标的正确方法吗?正如我提到的那样,这也应该工作3个月,例如应该依次检索“ 11月,12月,1月”和“ 12月,1月,2月”。