Thursday, December 15, 2011

Sql select statement, get data from todays date - 7 days ago?

hi,





i want to get all the data in my table having a certain baseset from seven days ago until today using my date_submitted format. Im new to this stuff so a help is greatly appreciated





sample table:


job_id | sms | logpoint | date_submitted | baseset


1 1 4400 thu sep 27,2010 10:10:10 setOne


2 2 4410 fri sep 27,2010 10:10:10 setTwo


3 3 4420 sat sep 27,2010 10:10:10 setOne





my sql:


select * from testing where baseset = 'setOne' and date_submitted = (what to put here)








thanks|||select * from testing where baseset = 'setOne' and date_submitted %26gt;= DATE_ADD(NOW(), INTERVAL -7 DAY)|||Actually, either of the above could be correct, depending on which DBMS you're using...the first works in MySQL while the second is for SQL Server. Oracle uses yet another different syntax. Since you specify MySQL, go with the first one.|||Simple





select * from testing where baseset = 'setOne' and date_submitted %26gt;=DATEADD(DAY,-7,GETDATE())

No comments:

Post a Comment