a b
1 2009
2 2007
3 2006
4 2010
5 2011
我如何从今天的年份中选择大于 5 年前的所有年份?
So it would be like 2013(year today) - 5 = 2008
a b
1 2009
4 2010
5 2011
我试过这个:
select * from table1 where b > CURRENT_TIMESTAMP - 5
我使用 smallint 作为 b 列的数据类型而不是日期,因为我将只存储年份。使用 small int 存储年份安全吗?
最佳答案
select * from table1 where b > DATEADD(YEAR,-5,GETDATE())
应该也可以
关于sql - 从今天的年份中选择大于 5 年前的所有年份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18342262/