简体   繁体   English

MySQL中相同月份/不同年份的时间戳比较

[英]Timestamp comparison in MySQL for same months / different years

I'm using SQL to query three tables for data analysis. 我正在使用SQL查询三个表以进行数据分析。 I need to compare timestamps for three months- Jan, Feb, March but over different years. 我需要比较三个月(一月,二月,三月,但不同年份)的时间戳。

My code so far for the WHERE clause is: 到目前为止,我在WHERE子句中的代码是:

a.time_stamp BETWEEN '%y%/10/01 00:00:00' AND '%y%/01/01 00:00:00'

and it is not returning the right result. 并且它没有返回正确的结果。 Any thoughts? 有什么想法吗?

MySQL lets you select the month from a date: MySQL使您可以从日期中选择月份:

select MONTH(now()); // -> 1 (in January)

so you might try (not tested): 因此您可以尝试(未经测试):

WHERE MONTH(a.time_stamp) >= 1 and MONTH(a.time_stamp) <=3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM