日期:2014-05-16  浏览次数:20930 次

关于排列
数据表结构
    mc       jg       sj
      1       10       2007-03-01
      1       20       2007-03-02
      2       5         2007-03-01
      2       10       2007-03-09
想要得到结果
    mc       jg       sj
    1         20       2007-03-02
    2         10       2007-03-09

------解决方案--------------------
--如果mc相同,取jg最大的记录

SELECT *
FROM 表名 as T
where not exists (select * from 表名 where mc=T.mc and jg> t.jg)

--如果mc相同,取sj最大的记录

SELECT *
FROM 表名 as T
where not exists (select * from 表名 where mc=T.mc and sj> t.sj)