数据如下:1         2            巢湖公安局     2013-02-04 14:43:56.000          1102         7            巢湖公安局     2013-02-05 10:01:47.000          1203         9            合肥公安局     2013-01-30 16:30:40.000          1804         10           合肥公安局     2013-01-28 16:30:06.000          170
筛选出的结果应该是,最新一条不重复(公安局的)记录2         7            巢湖公安局     2013-02-05 10:01:47.000          120
3         9            合肥公安局     2013-01-30 16:30:40.000          180

解决方案 »

  1.   

    select * from tb t where 时间=(select max(时间) from tb where 公安局=t.公安局)
      

  2.   

    select * from 表 a where 
    not exists (select 1 from 表 where a.第三个字段=第三个字段 and a.第四个字段<第四个字段) 
      

  3.   

    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',170select * 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*/
      

  4.   

    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
    2 7 巢湖公安局 2013-02-05 10:01:47.000 120
    3 9 合肥公安局 2013-01-30 16:30:40.000 180*/
      

  5.   

     
    1. select * from tb t where 时间=(select max(时间) from tb group by 公安局 where 公安局=t.公安局)
    2. select * from TB where not exists(select 1 from TB A where A.c=TB.c and A.d >TB.d)