表tb中有3字段Content,Createtime,Type例子如下         
Content   Createtime        Type
111 7/21/2010 15:36 Type one
222 7/21/2010 11:21 Type three
333 7/21/2010 11:20 Type one
444 7/21/2010 11:20 Type two
要求Type字段不重复,若有重复的,显示最新的
即查出结果如下:
111 7/21/2010 15:36 Type one
222 7/21/2010 11:21 Type three
444 7/21/2010 11:20 Type two
我新手,请问select查询语句应该怎样写啊?

解决方案 »

  1.   

    select * from TB  a where not exists(select 1 from TB where a.[Type]=[Type] and a.[Createtime]<[Createtime])
      

  2.   

    select * from tb where Content=(select min(Content) from tb a where a.one=one)
      

  3.   

    这样也行
    select * from tb where Content=(select top 1 Content from tb a where a.one=one order by Content)
      

  4.   

    看错了,还以为one是列名来的
    select * from tb where Content=(select min(Content) from tb a where a.Type=Type)
      

  5.   

    --> 测试数据:@TYPE
    declare @TYPE table([Content] int,[Createtime] datetime,[Type] varchar(19) )
    insert @TYPE
    select 111,'7/21/2010 15:36','Type1' union all
    select 222,'7/21/2010 11:21','Type3' union all
    select 333,'7/21/2010 11:20','Type1' union all
    select 444,'7/21/2010 11:20','Type2'select * from @TYPE  a where 1>
    (SELECT COUNT(*) from @TYPE where a.[Type]=[Type] and a.[Createtime]<[Createtime])