排除查询

EXPLAIN 
SELECT 
  t.* 
FROM
  `js_test` t 
WHERE (
    NOT EXISTS 
    (SELECT 
      * 
    FROM
      `js_test` f 
    WHERE f.`id` = t.`id` 
      AND f.`date` > t.`date`)
  ) ;

id	name	class	count	date
1	苹果	水果	10	2011-07-01
1	桔子	水果	20	2011-07-02
1	香蕉	水果	15	2011-07-03
2	白菜	蔬菜	12	2011-07-01
2	青菜	蔬菜	19	2011-07-02

猜你喜欢

转载自jis117.iteye.com/blog/2328953