【问题标题】:Load data for Last month when Insert date > 10th day of the month当插入日期 > 该月的第 10 天时加载上个月的数据
【发布时间】:2020-09-03 11:20:10
【问题描述】:

我有一个事实表,例如表 X。我需要编写一个查询以仅在插入日期大于该月的 10 日时加载上个月的数据。

【问题讨论】:

    标签: sql sql-server datetime where-clause


    【解决方案1】:

    您可以使用如下表达式获取当前月份的第 10 天:

    datefromparts(year(getdate()), month(getdate()), 10)
    

    如果您想从表列中计算此值,只需将 getdate() 替换为相关列名即可。

    虽然您希望如何在查询中使用此计算,但尚不清楚。如果您想过滤表中大于当月 10 日的insert_dates,您可以:

    select * from tablex where insert_date >= datefromparts(year(getdate()), month(getdate()), 10);
    

    如果你想在每个月的 10 号过滤,那么:

    select * from tablex where day(insert_date) >= 10
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-17
      • 1970-01-01
      • 2017-02-08
      • 1970-01-01
      相关资源
      最近更新 更多