我有一个事实表,例如表 X。我需要编写一个查询以仅在插入日期大于该月的 10 日时才加载上个月的数据。
1 回答
0
您可以使用如下表达式获取当前月份的第 10 天:
datefromparts(year(getdate()), month(getdate()), 10)
如果你想从一个表列中计算出来,你可以getdate()
用相关的列名替换。
不过,目前还不清楚您希望如何在查询中使用此计算。如果要过滤表中insert_date
大于当月 10 日的 s,可以执行以下操作:
select * from tablex where insert_date >= datefromparts(year(getdate()), month(getdate()), 10);
如果你想在每个月的 10 号过滤,那么:
select * from tablex where day(insert_date) >= 10
于 2020-09-03T11:22:39.227 回答