日期:2014-05-17 浏览次数:20492 次
select * from tb t where 时间=(select max(时间) from tb where 公安局=t.公安局)
if object_id('[TB]') is not null drop table [TB]
go
create table [TB] (a int,b int,c nvarchar(10),d datetime,e int)
insert into [TB]
select 1,2,'巢湖公安局','2013-02-04 14:43:56.000',110 union all
select 2,7,'巢湖公安局','2013-02-05 10:01:47.000',120 union all
select 3,9,'合肥公安局','2013-01-30 16:30:40.000',180 union all
select 4,10,'合肥公安局','2013-01-28 16:30:06.000',170
select * from TB where not exists(select 1 from TB A where A.c=TB.c and A.d <TB.d)
/*
a b c d e
1 2 巢湖公安局 2013-02-04 14:43:56.000 110
4 10 合肥公安局 2013-01-28 16:30:06.000 170*/