gpt4 book ai didi

SQL Server : How to get rows where the date is older than X years?

转载 作者:行者123 更新时间:2023-12-03 15:08:54 25 4
gpt4 key购买 nike



我想从数据库中提取所有 Assets ,该数据库已有一定的历史,在这种情况下为年。这个说法正确吗?

背景

该数据库名为 AssetRegister
该表名为 dbo.Assets
该列名为 AcquiredDate
迄今为止的声明

SELECT * FROM dbo.Assets WHERE AcquiredDate < '2008-01-01'

最佳答案

SELECT * FROM dbo.Assets                  
WHERE DATEDIFF(YEAR, AcquiredDate, GetDate()) >= 8

有关性能优化的查询,请查看 @Horaciuxs answer .

关于SQL Server : How to get rows where the date is older than X years?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26990053/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com