SQL query for getting data for last 3 months(用于获取过去 3 个月数据的 SQL 查询)
问题描述
如何获取今天的日期并将其转换为01/mm/yyyy
格式并从表中获取3 个月前交货月份的数据?表中已包含交货月份 01/mm/yyyy
.
How can you get today's date and convert it to 01/mm /yyyy
format and get data from the table with delivery month 3 months ago? Table already contains delivery month as 01/mm/yyyy
.
推荐答案
SELECT *
FROM TABLE_NAME
WHERE Date_Column >= DATEADD(MONTH, -3, GETDATE())
Mureinik 建议的方法将返回相同的结果,但通过这种方式,您的查询可以从 Date_Column
上的任何索引中受益.
Mureinik's suggested method will return the same results, but doing it this way your query can benefit from any indexes on Date_Column
.
或者您可以检查过去 90 天.
or you can check against last 90 days.
SELECT *
FROM TABLE_NAME
WHERE Date_Column >= DATEADD(DAY, -90, GETDATE())
这篇关于用于获取过去 3 个月数据的 SQL 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:用于获取过去 3 个月数据的 SQL 查询


基础教程推荐
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01