我一直在搜索此内容,但只获得了指定日期的答案。从当前月份和上个月的特定日期之间选择
我现在面临的问题是:
返回所有比上月的20日和本月的20日之间的数据。
select name, data, activity from Table
where (year(data) = year(getdate()) and month(data) = month(getdate())-1 and day(data) >= 20) and (year(data) = year(getdate()) and month(data) = month(getdate()) and day(data) <= 20)
select name, data, activity from Table
where year(data) = year(getdate()) and month(data) >= month(getdate())-1 and day(data) >= 20
这最后一个会工作,但它不会返回当前月份的任何结果。
我已经尝试了几个where子句,但它只接受指定日期的接缝。有没有办法动态地做到这一点?
感谢
感谢@Gordon,但它接缝该公司正在使用SQL Server 2008,仅2012年来的有没有什么办法来模拟2008年EOMONTH EOMONTH的?谢谢 –