加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Mysql查询按月和年获取结果

发布时间:2020-12-13 17:26:23 所属栏目:PHP教程 来源:网络整理
导读:表inventory_month有三个字段id,month_month和month_year id month_month month_year1 09 20122 10 2012 3 11 20124 01 20135 02 20136 03 20137 09 2013 8 10 2013 我需要从2012年10月到2013年10月的结果如下 预期结果 id month_month month_year2 10 2012
表inventory_month有三个字段id,month_month和month_year

id month_month month_year
1  09          2012
2  10          2012  
3  11          2012
4  01          2013
5  02          2013
6  03          2013
7  09          2013 
8  10          2013

我需要从2012年10月到2013年10月的结果如下

预期结果

id month_month month_year

2  10          2012  
3  11          2012
4  01          2013
5  02          2013
6  03          2013
7  09          2013 
8  10          2013

但是得到的结果如下

得到结果

id month_month month_year

2  10          2012 
8  10          2013

我在下面尝试过查询

选择id,month_month,month_year,其中month_month> = 10 AND month_year> = 2012 AND month_month< = 10 AND month_year< = 2013 需要有用的建议,谢谢!

解决方法

使用,

SELECT id,month_year WHERE
(month_month >= 10 AND month_year = 2012)
OR     
(month_month <= 10 AND month_year = 2013)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读