简体   繁体   English

从今天开始选择大于5年前的所有年份

[英]select all years that greater than 5 years ago from year today

 a          b
 1          2009
 2          2007
 3          2006
 4          2010
 5          2011

How I will select all years that greater than 5 years ago from year today? 从今天到现在,我将如何选择大于5年前的所有年份?

So it would be like 2013(year today) - 5 = 2008
 a          b
 1          2009
 4          2010
 5          2011

I tried this: 我尝试了这个:

select * from table1 where b > CURRENT_TIMESTAMP - 5

I use smallint as datatype of column b instead of date because I will only store the year. 我将smallint用作b列的数据类型而不是日期,因为我只会存储年份。 Is it safe to use small int for storing year? 使用小整数存储年份安全吗?

您接近:

select * from table1 where b > YEAR(CURRENT_TIMESTAMP) - 5
select * from table1 where b > DATEADD(YEAR,-5,GETDATE())

应该也可以

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

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