SQL-仅获取当前年份的结果 [英] SQL - Get result of current year only

查看:552
本文介绍了SQL-仅获取当前年份的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用SQL获取当年的结果?

How can I get the result of the current year using SQL?

我有一个表,该表的列日期格式为yyyy-mm-dd.

I have a table that has a column date with the format yyyy-mm-dd.

现在,我要选择仅返回当前年份结果的查询.

Now, I want to do select query that only returns the current year result.

伪代码应类似于:

select * from table where date is (current year dates)

结果应如下:

id date
2  2015-01-01
3  2015-02-01
9  2015-01-01
6  2015-02-01

我该怎么做?

推荐答案

使用

Use YEAR() to get only the year of the dates you want to work with:

select * from table where YEAR(date) = YEAR(CURDATE())

这篇关于SQL-仅获取当前年份的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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