【问题标题】:How to filter a specific record in SQL Server within in the date range without removing other records?如何在日期范围内过滤 SQL Server 中的特定记录而不删除其他记录?
【发布时间】:2020-04-28 00:14:57
【问题描述】:

我正在使用 SSMS 2017。

下面是源表,

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

其中日期差>=6个月,满足以下条件(date2

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

【问题讨论】:

    标签: sql tsql ssms-2017


    【解决方案1】:

    这是你想要的吗?

    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)
    

    【讨论】:

      猜你喜欢
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 1970-01-01
      • 2020-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多