表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查询语句应该怎样写啊?
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查询语句应该怎样写啊?
select * from tb where Content=(select top 1 Content from tb a where a.one=one order by Content)
select * from tb where Content=(select min(Content) from tb a where a.Type=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])