在SQL中显示超过3个月的记录 [英] Display record older than 3 months in sql
本文介绍了在SQL中显示超过3个月的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建一个SSIS程序包,该程序将通过一个在 3个月内的table(T1)
记录中的记录(基于ALERT_TIMESTAMP
)并将其移动到另一个table(T2)
I need to create a SSIS package that will go through the records in one table(T1)
older than 3 months (based on ALERT_TIMESTAMP
) and move them to another table(T2)
我的查询是:
SELECT * FROM T1
WHERE (DATEDIFF([month], ALERT_TIMESTAMP, GETDATE()) > 3)
Alert_timestamp
列为Datetime
格式.例如:'10/26/2012 12:00:00 AM'
当我运行查询时,它应该显示所有早于 3个月的记录,但不会.
When I run the query it should display all the records that are older than 3 months, but it does not.
推荐答案
尝试一下
select * from `table` where `yourfield` >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH)
年份,年份请参见以下示例.
For days, year see below for example.
DATE_SUB(CURDATE(), INTERVAL 15 DAY) /*For getting record specific days*/
DATE_SUB(CURDATE(), INTERVAL 1 YEAR) /*for getting records specific years*/
对于Anand,查询
For Anand, query
BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH ) AND DATE_SUB( CURDATE() ,INTERVAL 3 MONTH )
/* For Getting records between last 6 month to last 3 month
这篇关于在SQL中显示超过3个月的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文