日期:2014-05-17  浏览次数:20469 次

sql 查询问题 .求解决!!!
 filesid  filesname     filesversion   path                        filesUpLoadDate
 6 新建文本文档.txt 1.0.0.0 //update//新建文本文档.txt 2012-11-15 16:24:30.820
 7 新建文本文档.txt 1.0.0.1 //update//新建文本文档.txt 2012-11-15 16:31:16.377
 8 李剑锋.txt 1.0.0.0 //update//李剑锋.txt 2012-11-15 16:42:55.757
 9 李剑锋.txt 1.0.0.1 //update//李剑锋.txt 2012-11-15 16:42:58.480
 10 李剑锋.txt 1.0.0.2 //update//李剑锋.txt 2012-11-15 17:48:55.663
 ....当然这里还有很多数据.
 无论它有多少,我现在以文件名称 列(filesname 去掉相同的 ) 拿到 
  最新版本(filesversion )为最高的 
以上数据 查出结果为:
 7 新建文本文档.txt 1.0.0.1 //update//新建文本文档.txt 2012-11-15 16:31:16.377
 10 李剑锋.txt 1.0.0.2 //update//李剑锋.txt 2012-11-15 17:48:55.663 
 请问sql 语句该怎么写 .
------最佳解决方案--------------------
  select a.*
  from tablename as a inner join (select filename,MAX(fileuploaddate) fileuploaddate from tablename group by filesname) as b
   on a.filesname=b.filesname and a.fileuploaddate=b.fileuploaddate
 
------其他解决方案--------------------
SELECT  *
 FROM    TB a
 WHERE   EXISTS ( SELECT 1
                  FROM   ( SELECT    filesname ,
                                     MAX(filesversion) filesversion
                           FROM      TB
                           GROUP BY  filesname
                         ) b
                  WHERE  a.filesname = b.filesname
                         AND a.filesversion = b.filesversion )

------其他解决方案--------------------
select a.*
  from tablename as a inner join (select filename,MAX(fileuploaddate) fileuploaddate from tablename group by filesname) as b
   on a.filesname=b.filesname and a.fileuploaddate=b.fileuploaddate
理解万岁..........
------其他解决方案--------------------
查询所有信息
------其他解决方案--------------------
select filesid,filesname,filesversion,path,filesUpLoadDate from tb as a
where not exists(select 1 from tb as x where x.filesname=a.filesname and x.filesUpLoadDate>=a.filesUpLoadD