表如下:
SID    STime
1      2009-1-1
2      2009-1-1
3      2009-1-1
4      2009-1-1
1      2009-1-2
2      2009-1-2
3      2009-1-2
4      2009-1-2
1      2009-1-3
2      2009-1-3
3      2009-1-3
4      2009-1-3
1      2009-1-4
2      2009-1-4
3      2009-1-4
4      2009-1-4我想查询日期最新的SID数据用了Group by 都不行!请教各位大侠了。

解决方案 »

  1.   


    select distinct sid 
    from t
    where sTime = (select max(Stime) from t)
      

  2.   


    --TRY
    select a.* from tb a where not exists(select 1 from tb where SID = a.SID and STIME > a.STIME)
      

  3.   

    select top 1 sid,stime
    from table
    order by stime desc
      

  4.   


    select sid 
    from yourtable
    where sTime >= ALL(select Stime from yourtable)
      

  5.   

    速度确实太快了!!呵呵。感谢第一位给我答案的人。谢谢。最后我采取了:
    select sid 
    from t
    where sTime = (select max(Stime) from t)
    得出结果!有没有不用查询两次的?呵呵