MySQL查询月份年份 [英] MySQL query for month year

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

问题描述

我有一个包含以下字段的表格

I have a table with following fields

id (int)
name (varchar)
dob (datetime)

现在我需要一个可以同时匹配月份和年份的查询

Now I need a query that can match month and year at same time

我现在正在使用的是

select * from users where month(dob)='12' and year(dob)='2010'

我不想使用month()和year(),可以单件完成吗?

I don't want to use month() and year(), can it be done in single thing?

感谢帮助

谢谢

推荐答案

它可以根据您的要求进行表达,但我认为这样做不会更加有效.

It can be expressed as you request, but I don't think it would be any more efficient.

where dob >= '2010-12-01' and dob <= '2010-12-31 23:59:59'

where '201012' = date_format(dob,'%Y%m')

这篇关于MySQL查询月份年份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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