select a.* from tablename a,(select softType,max(AddTime) as AddTime from tablename group by softType) as b where a.softType=b.softType and a.AddTime=b.AddTime
我在SQL SERVER2000 下做过测试成功1、建立一个测试表数据如下:表名:softwareaddTime softType 2002-05-01 a 2002-05-02 b 2002-05-03 b 2002-05-01 c 2002-05-02 c 2002-05-01 d 2002-05-02 d 2002-05-01 e 2002-05-02 e 2002-05-01 f 2002-05-02 f 2002-05-02 a
按你的要求写的SQL 语句如下: SELECT MAX(addTime) AS 最新日期, softType AS 版本 FROM software GROUP BY softType执行后返回数据如下: 最新日期 版本 2002-05-02 a 2002-05-03 b 2002-05-02 c 2002-05-02 d 2002-05-02 e 2002-05-02 f
select softType,max(AddTime) as AddTime from software group by softType
(select count(sortype) from addTime>=a.addTime and sortType=a.sortType)=1
如果存在重复的sortype,用count(distinct sorttype)试试
仅限于SQL,ACCESS就不不敢保证了!
2002-05-01 a
2002-05-02 b
2002-05-03 b
2002-05-01 c
2002-05-02 c
2002-05-01 d
2002-05-02 d
2002-05-01 e
2002-05-02 e
2002-05-01 f
2002-05-02 f
2002-05-02 a
按你的要求写的SQL 语句如下:
SELECT MAX(addTime) AS 最新日期, softType AS 版本
FROM software
GROUP BY softType执行后返回数据如下:
最新日期 版本
2002-05-02 a
2002-05-03 b
2002-05-02 c
2002-05-02 d
2002-05-02 e
2002-05-02 f