id                                     opt_date                 bar_code
09FBBAC3AD5E2F4A81550DF968B449BA    2012-04-22 12:55:31         0000777777
4D332D57B7374C439EB66B7DCC1D7FCC    2012-04-23 12:56:51         0000777777
B8CFE31D9512CB4CA0C8E24BC66FA3AD    2012-04-24 12:55:41         0000777777
FF00F2D8A253F243A4DBF3725950348E    2012-04-25 12:56:01         0000777777经过查询,取出opt_date日期值最大的那条完整记录id                                     opt_date                 bar_code
FF00F2D8A253F243A4DBF3725950348E    2012-04-25 12:56:01         0000777777 

解决方案 »

  1.   


    select * from tb b where not exists (select 1 from tb a where a.id=b.id and a.time>b.time)
      

  2.   


    SELECT TOP 1 * FROM tb ORDER BY opt_date DESC
      

  3.   


    select top 1 * from  table order by opt_date desc
      

  4.   

    select * from tb b where not exists (select 1 from tb a where a.id=b.id and a.time>b.time)按这种方法执行下来还是显示4条数据,不知道什么情况
      

  5.   

    select s.* from(
    select *from your_table order by opt_date) s where rownum=1
      

  6.   

    刚看错了 发的oracle 里面的
    sql server中
    SELECT TOP 1 * FROM tb ORDER BY opt_date DESC
    三楼正解
      

  7.   


    --最大值唯一
    SELECT TOP 1 * FROM tb ORDER BY opt_date DESC
    --最大值不唯一
    select * from tb b where not exists (select 1 from tb a where a.id=b.id and a.time>b.time)