读书人

关于排列解决方案

发布时间: 2012-02-07 17:45:37 作者: rapoo

关于排列
数据表结构
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)

读书人网 >Access

热点推荐