繁体   English   中英

如何在日期范围内过滤 SQL 服务器中的特定记录而不删除其他记录?

[英]How to filter a specific record in SQL Server within in the date range without removing other records?

我正在使用 SSMS 2017。

下面是一个源表,

源表

从上表中,我只想过滤“i”记录

需要删除的记录

通过满足以下条件 (date2 <= dateadd(MONTH, +6, date1 - datepart(MONTH, date1) -1)),日期差 >=6 个月,结果应如下所示,

结果表

任何人的任何帮助都将不胜感激。

这是你想要的吗?

select t.*
from t
where name <> 'i' or
      date2 <= dateadd(month, +6, date1 - datepart(month, date1) -1))

我不太确定你的情况应该是什么,但这就是你的问题。

根据文中的逻辑:

select t.*
from t
where name <> 'i' or
      date2 <= dateadd(month, +6, date1)

暂无
暂无

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

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