日期:2014-05-16 浏览次数:20997 次
mysql> select * from test; +----+------+--------------+------------+ | id | cid | title | pubdate | +----+------+--------------+------------+ | 1 | 1 | 测试通知新闻 | 2011-12-05 | | 2 | 2 | 测试通知新闻 | 2011-12-05 | | 3 | 3 | 测试通知新闻 | 2011-12-04 | | 4 | 1 | 测试新闻1 | 2011-12-04 | | 5 | 2 | 测试新闻2 | 2011-12-04 | | 6 | 3 | 测试新闻3 | 2011-12-03 | | 7 | 4 | 测试新闻4 | 2011-12-02 | | 8 | 2 | 测试新闻5 | 2011-12-02 | | 9 | 1 | 测试新闻6 | 2011-12-02 | | 10 | 2 | 测试新闻7 | 2011-12-01 | | 11 | 3 | 测试通知新闻 | 2011-12-01 | | 12 | 2 | 测试通知新闻 | 2011-11-30 | | 13 | 3 | 测试新闻9 | 2011-11-30 | | 14 | 1 | 测试新闻10 | 2011-11-30 | | 15 | 4 | 测试新闻12 | 2011-11-28 | | 16 | 2 | 测试通知新闻 | 2011-11-27 | +----+------+--------------+------------+ 16 rows in set (0.01 sec) mysql> select * -> from test a -> where cid in (1,2,3) -> and not exists ( -> select 1 from test -> where id<a.id and title=a.title -> and pubdate between a.pubdate-interval 2 day and a.pubdate+interval 2 day -> ); +----+------+--------------+------------+ | id | cid | title | pubdate | +----+------+--------------+------------+ | 1 | 1 | 测试通知新闻 | 2011-12-05 | | 4 | 1 | 测试新闻1 | 2011-12-04 | | 5 | 2 | 测试新闻2 | 2011-12-04 | | 6 | 3 | 测试新闻3 | 2011-12-03 | | 8 | 2 | 测试新闻5 | 2011-12-02 | | 9 | 1 | 测试新闻6 | 2011-12-02 | | 10 | 2 | 测试新闻7 | 2011-12-01 | | 11 | 3 | 测试通知新闻 | 2011-12-01 | | 13 | 3 | 测试新闻9 | 2011-11-30 | | 14 | 1 | 测试新闻10 | 2011-11-30 | | 16 | 2 | 测试通知新闻 | 2011-11-27 | +----+------+--------------+------------+ 11 rows in set (0.00 sec) mysql>