t1 
date                                 id 
2008-02-26 09:46:37.737 139 46000 
2008-02-26 20:22:28.357 139 46000 t2 id  
46000 结果 2008-02-26 09:46:37.737 139 46000

解决方案 »

  1.   

    我用以下语句:
    select *
    from T1 a
    where not exists(select 1 from T1 where  imsi= a.imsi and  timeStamp>a.timeStamp)取得的是时间最大的一条。这条语句理解上应该是时间最小才对阿,
      

  2.   

    select t2.id,max(date)
    from t1 inner join t2 on t1.id=t2.id
    group by t2.id[align=center]====  ====
    [/align]
      

  3.   


    declare @a table(date int ,ID int)
    insert into @a select 100,5
    insert into @a select 175,5
    insert into @a select 175,6
    insert into @a select 220,6declare @b table(ID int)
    insert into @b select 5
    insert into @b select 6
    --最小
    select a.id,min(date)
    from @a a inner join @b b on a.id=b.id
    group by a.id
    --最大
    select a.id,max(date)
    from @a a inner join @b b on a.id=b.id
    group by a.id
    --第一条
    select c.*
    from (select a.* from @a a where date=(select top 1 date from @a b where ID=a.ID )) c 
    inner join @b b on c.id=b.id
    --随机一条
    select c.*
    from (select a.* from @a a where date=(select top 1 date from @a b where ID=a.ID order by newid())) c 
    inner join @b b on c.id=b.id
      

  4.   

    还有其他列,用GROUP BY 不行
      

  5.   

    不太明白楼主的意思.
    select top 1 * from t1 join t2 on t1.id = t2.id order by t1.date 
      

  6.   

    declare @id int,@date datetime
    declare mycursor cursor for
    select date,id from t1 
    open mycursor
    fetch NEXT from mycursor into @date,@id
       select t1.id,t1.date from t1 join t2 
    on t1.id=t2.id
    where t1.date=@date and t1.id=@id
    close mycursor
    deallocate mycursor不太懂你要实现这个做什么,但我这样是能实现
      

  7.   


    select a.* from t1 a ,t2 b
    where  a.id=b.id and not exists(select 1 from t1 c where a.id=c.id and a.date<c.date)