sql查询获取最近3个月的数据 [英] sql query for getting data for last 3 months

查看:1605
本文介绍了sql查询获取最近3个月的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取今天的日期并将其转换为 01 / mm / yyyy 格式,并从交货月份的3个月前的表格中获取数据?表已经包含交货月份为 01 / mm / yyyy

解决方案

  SELECT * 
FROM TABLE_NAME
WHERE Date_Column> = DATEADD(MONTH,-3,GETDATE())
pre>

Mureinik建议甲方将返回相同的回复。但是这样做,您的查询可以从 Date_Column 中的任何索引中受益。



或者您可以检查过去90天。

  SELECT * 
FROM TABLE_NAME
WHERE Date_Column> = DATEADD(DAY,-90,GETDATE ))


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 suggested methond will return the same resutls. but doing this way your query can benefit from any indexes on Date_Column.

or you can check against last 90 days.

SELECT * 
FROM TABLE_NAME
WHERE Date_Column >= DATEADD(DAY, -90, GETDATE()) 

这篇关于sql查询获取最近3个月的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆