日期:2014-05-17 浏览次数:20510 次
select * from table a
where not exists(select * from table where type=a.type and [datatime]='1900-01-01')
and not exists(select * from table where type=a.type and [datetime]>a.[datetime])
create table ht
(ID int,[type] int,[DATETIME] datetime,[count] int)
-- 如果DATETIME 3列中包含1900-01-01 则查询不显示
truncate table ht
insert into ht
select 1,10,'2013-12-08 11:59:42.640',2 union all
select 2,10,'2013-12-08 09:20:10.450',2 union all
select 3,10,'1900-01-01 00:00:00.000',0
select top 1 [DATETIME] from ht
where not exists(select 1 from ht
where convert(varchar,[DATETIME],23)='1900-01-01')
order by [DATETIME] desc
/*
DATETIME
-----------------------
(0 row(s) affected)
*/
-- 如果DATETIME 3列中不包含1900-01-01 则显示DATETIME 最大值
truncate table ht
insert into ht
select 1,10,'2013-12-08 11:59:42.640',2 union all
&n