f1 f2 f3
10 a 1
10 b 2
11 c 5
11 d 2
11 e 4
12 f 9
12 g 7
我想得到
f1 f2 f3
10 a 1
11 d 2
12 g 7
也就是说:相同的f1只取1条记录,这1条是相同f1所有记录中 f3最小的

解决方案 »

  1.   

    http://topic.csdn.net/u/20080123/18/9731d130-0d4b-4c11-8d89-f2c3ca331f0c.html
      

  2.   


    select  * from 表名 a where not exists(select 1 from 表名 where f1=a.f1 and f3<a.f3)
      

  3.   

    select * from tb a
    where not exists(
    select 1 from tb where f1=a.f1 and f3<a.f3
    )
      

  4.   


    --or
    select  * from 表名 a where f3 in(select max(f3) from 表名 where f1=a.f1)--or
    select  * from 表名 a where (select count(distinct f3) from 表名 where f1=a.f1 and f3<=a.f3)=1
      

  5.   

    declare @tb table (f1 int,f2 varchar(10),f3 int)
    insert into @tb select 10,'a',1
    insert into @tb select 10,'b',2
    insert into @tb select 11,'c',5insert into @tb select 11,'d',2
    insert into @tb select 11,'e',4
    insert into @tb select 12,'f',9
    insert into @tb select 12,'g',7
    select * from @tb a
    where not exists(
    select 1 from @tb where f1=a.f1 and f3 <a.f3
    )
    f1 f2 f3
    10 a 1
    11 d 2
    12 g 7
      

  6.   

    f1 f2 f3 
    10 a 1 
    10 b 2 
    11 c 5 
    11 d 2 
    11 e 4 
    12 f 9 
    12 g 7 
    我想得到 
    f1 f2 f3 
    10 a 1 
    11 d 2 
    12 g 7 
    也就是说:相同的f1只取1条记录,这1条是相同f1所有记录中 f3最小的select t.* from tb t where f3 = (select min(f3) from tb where f1 = t.f1)
      

  7.   

    不过..有个问题 如果F3有重复值就不能搞了
    例如
    13 h 6
    14 i 6