一数据表中有如下数据:
第一列是编号,第二列是内容,第三列是时间
 F183S-T0201      9998                 4/26/2006 5:11:50 PM               
 F183S-T0201      9998                 4/29/2006 5:14:04 PM               
 F183S-T0201      9998                 4/30/2006 5:18:23 PM               
 F183S-T0222      9998                 4/26/2006 5:11:50 PM               
 F183S-T0222      9998                 4/29/2006 5:14:04 PM               
 F183S-T0222      9998                 4/30/2006 5:18:23 PM   想选出一组数据:每个编号的最晚一条记录,也就是时间值最大的记录   
 F183S-T0201      9998    4/30/2006 5:18:23 PM        
 F183S-T0222      9998    4/30/2006 5:18:23 PM 怎么用一条SQL语句实现此功能呢?

解决方案 »

  1.   

    select * from tb t where not exists(select * from tb where 第一列是编号=t.第一列是编号 and 第三列是时间<t.第三列是时间)
      

  2.   

    select * from tb t
    where not exists(select 1 from tb where 编号=t.编号 and 时间>t.时间)
      

  3.   

    select t.* from tb t where 时间 = (select max(时间) from tb where 编号 = t.编号)select t.* from tb t where not exists (select 1 from tb where 编号 = t.编号 and 时间 > t.时间)
      

  4.   

    select * from tb t where 时间 = (select max(时间) from tb where 编号 = t.编号)
      

  5.   

    select * from tb t where 时间 = (select max(时间) from tb where 编号 = t.编号)