Display record older than 3 months in sql

前端 未结 2 1204
南方客
南方客 2020-12-17 20:38

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) a

相关标签:
2条回答
  • 2020-12-17 21:06

    Try this

    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*/
    


    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
    
    0 讨论(0)
  • 2020-12-17 21:11

    What you posted is not MySQL. Assuming you are using MS SQL Server, you should use the ABS() function.

    SELECT   * FROM        T1
    WHERE     ABS(DATEDIFF([month], ALERT_TIMESTAMP, GETDATE())) > 3
    
    0 讨论(0)
提交回复
热议问题