表结构
(
sn int,
id int,
time datetime
)
求 id=1、time最大的记录的sn

解决方案 »

  1.   

    select top 1 sn from 表 where id=1 order by time desc
      

  2.   

    select 
        t.sn 
    from 
        表 t 
    where 
        t.id=1 
        and 
        not exists(select 1 from 表 where id=t.id and time>t.time)
      

  3.   

    select id,max(b) sn from [表] where id=1 group by id
      

  4.   

    :)
    select * from [表] where [time]=(select max([time]) from [表] where id=1 group by id)
      

  5.   

    select sn
    from 表
    where id=1 and time=(select max(time) from 表 where id=1 group by id)