mysql返回匹配年月的行 [英] mysql return rows matching year month

查看:31
本文介绍了mysql返回匹配年月的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何进行查询,该查询返回包含查询时当前年份和月份日期的所有行的结果.

How would I go about doing a query that returns results of all rows that contain dates for current year and month at the time of query.

每行的时间戳格式如下:yyyy-mm-dd

Timestamps for each row are formated as such: yyyy-mm-dd

我知道它可能与日期函数有关,并且我必须以某种方式设置一个特殊参数以使其像这样吐出:yyyy-mm-%%.

I know it probably has something to do with the date function and that I must somehow set a special parameter to make it spit out like such: yyyy-mm-%%.

将日期设置为通配符可以解决问题,但我似乎不知道该怎么做.

Setting days to be wild card character would do the trick but I can't seem to figure it out how to do it.

这里是一个链接,可以快速参考 mysql 中的日期时间函数:

Here is a link to for quick reference to date-time functions in mysql:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

谢谢

推荐答案

我认为 EXTRACT 是您正在寻找的功能:

I think EXTRACT is the function you are looking for:

SELECT * FROM table
WHERE EXTRACT(YEAR_MONTH FROM timestamp_field) = EXTRACT(YEAR_MONTH FROM NOW())

这篇关于mysql返回匹配年月的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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