2013-02-09 67 views
1

我是SQL新手。我有一個包含廣告信息的表格。我應該使用哪個功能來查找過去三天內發佈的所有廣告的ID?查找過去三天內發佈的所有廣告的ID,Sql

+0

[RDBMS](http://en.wikipedia.org/wiki/Relational_database_management_system)您使用的是什麼? 'SQL Server'? 'MySQL'? 'Oracle'? 'DB2'? – 2013-02-09 07:20:50

+0

另外,發佈表結構。 – Orangecrush 2013-02-09 07:21:28

+0

@JW,甲骨文。它包含以日期爲域的pdate,以及其他一些信息 – 2013-02-09 07:25:58

回答

1

對於Oracle數據庫,利用這一點,

SELECT id 
FROM tablename 
WHERE TRUNC(pdate) >= TRUNC(SYSDATE) - 3; 

SQLFIDDLE DEMO

+0

謝謝,它的工作原理。你能解釋一下,「DUAL」在這裏做什麼? – 2013-02-09 07:37:43

+1

@MarshallBlack關於[DUAL]的信息(http://stackoverflow.com/questions/73751/what-is-the-dual-table-in-oracle) – Orangecrush 2013-02-09 07:40:54

+0

yeap,我正要這樣做,只是在閱讀有關雙 – 2013-02-09 07:44:55

1
Select ID --the id field 
From tblAds --the ads table 
WHERE Ad_Date >= DATEADD(day,-3,getDate()) --the filter. I am assuming Ad-Date is the name of the ad's date field 
order by Ad_Date ASC -- order it 
+0

「日期添加 - 無效標識符」。我收到此消息 – 2013-02-09 07:35:22

+0

Google Oracle DateAdd函數。 – 2013-02-09 16:03:40

相關問題