View previous topic :: View next topic
|
Author |
Message |
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
Need a query to find 30 days old data from a table. Need to compare with time stamp column. whenever the sql is executed it need to fetch the 30 days old data by using time stamp column. |
|
Back to top |
|
|
vickey_dw
New User
Joined: 10 Jun 2015 Posts: 51 Location: India
|
|
|
|
Try below
Code: |
Select * from table-name where
(column_name > (Current_TimeStamp - 30 Days)) |
Looks like first time i have contributed |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
Back to top |
|
|
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
I need to fetch the last 30 days record. Whenever my query is running it need to fetch the last 30 days record.
I tried the below one its not working
SELECT * FROM Test.Test1_ABC
WHERE DATE(timestamp) = CURRENT DATE - 30 DAY ..
trying for other options..pls let me know if anything needs to be changed |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
|
|
Quote: |
I tried the below one its not working |
Please post the error without that no one can help here better. |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Quote: |
I tried the below one its not working
SELECT * FROM Test.Test1_ABC
WHERE DATE(timestamp) = CURRENT DATE - 30 DAY ..
trying for other options..pls let me know if anything needs to be changed |
This should work perfectly well provided you put the right column name. Are you using the correct column name?:
Quote: |
WHERE DATE(Column Name containing timestamp in table Test1_ABC) = CURRENT DATE - 30 DAY |
This is the only piece which could go wrong here.
. |
|
Back to top |
|
|
mf_karthik
New User
Joined: 26 Jul 2005 Posts: 55
|
|
|
|
Rohit Umarjikar wrote: |
Quote: |
I tried the below one its not working |
Please post the error without that no one can help here better. |
NO rows retrieved |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3049 Location: NYC,USA
|
|
|
|
Then there must not be any rows. and your one line answer would not solve the issue, please provide specific data as it works at my end. |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
Oh.. And one more thing. You will need '>=' in place of '=' If you want the data for last 30 days and Not the 30th day only.
. |
|
Back to top |
|
|
|