假设我在一个表中有 2 个字段: 年 月份
我如何对这些数据进行排序,以便我可以读取给定组合的最后 12 个条目。例如Year=2019, month=1 我希望数据库为 bach 提供 2019 年 1 月、2018 年 12 月等的数据。
使用mysql和limit。
最佳答案
嗯,这对你的数据有效吗?
select t.*
from t
where year * 100 + month < 2019 * 100 + 1
order by year desc, month desc
limit 12;
关于mysql - 对两个字段的数据进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54479947/