表格有这样的结构:
code | item | trimester | year
1 rrr 1 2014
2 fff 3 2014
3 ggg 3 2014
4 hhh 4 2015
5 ttt 2 2016
6 fff 3 2016
现在我想选择 2014 年第 3 学期和 2016 年第 1 学期之间的所有项目,你怎么能这样做?
此示例表的查询结果可能是:
2 fff 3 2014
3 ggg 3 2014
4 hhh 4 2015
最佳答案
一种方法:
where year * 10 + trimester between 20143 and 20161
或者,您可以明确:
where (year > 2014 or (year = 2014 and trimester >= 3)) and
(year < 2016 or (year = 2016 and trimester = 1))
关于mysql - 如何在初始三个月/年和最后三个月/年之间选择 MySQL 中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39323276/