MySQL - 几个月之间(而不是时间戳) [英] MySQL - Between months (rather than a timestamp)

查看:158
本文介绍了MySQL - 几个月之间(而不是时间戳)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何生成一个MySQL查询以获取特定月份
之间的行,例如:从01/01(1月1日)到01/06(6月1日)之间的月份的抓取行

解决方案

我不确定,如果要从1月到6月抓住所有行,只有行至6月1日或1月至5月的所有行。您可以使用例如:

  [...] WHERE`date_column` BETWEEN'2012- 01-01'AND'2012-06-01'

其中包括6月1日的所有行。



使用此功能从1月至6月的整个月内获取所有行:

 BETA 1 AND 5  


how would I generate a MySQL query to grab a row that is between a particular month eg grab row where month is between 01/01 (1st Jan) and 01/06 (1st June)

解决方案

I'm not sure, if you want to grab all rows from Jan to June, only the rows until June 1st or all rows from Jan to May. You can use for example:

[...] WHERE `date_column` BETWEEN '2012-01-01' AND '2012-06-01'

which gives you all rows including June 1st.

Use this to get all rows from the full months of Jan to June:

[...] WHERE YEAR(`date_column`)=2012 AND MONTH(`date_column`) BETWEEN 1 AND 6

(change to BETWEEN 1 AND 5 for Jan to May)

这篇关于MySQL - 几个月之间(而不是时间戳)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆