如何在SQL Server中获取日期的不同年份? [英] How to fetch distinct year from date in SQL server?
本文介绍了如何在SQL Server中获取日期的不同年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
数据库结构为
ItemID DOE
001 2012-03-25
002 2011-03-25
003 2010-03-25
004 2012-05-25
doe字段数据类型为Date
如何从此表中获得不同的年份?
Database structure is
ItemID DOE
001 2012-03-25
002 2011-03-25
003 2010-03-25
004 2012-05-25
doe field datatype is Date
How to get distinct year from this table?
推荐答案
尝试以下方法:
Try this:
SELECT DISTINCT DATEPART(year, date) as year FROM TableName
这篇关于如何在SQL Server中获取日期的不同年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文