有表如下,
table: table1
conNo ,conbno,f1,f2
1000,  0,YY,DD
1000,  1,hh,ll
1000,  2,pp,kk
1001,  0,qq,qq
1002,  0,gg,gg求一条SQL,执行后的结果如下,
1000,  2,pp,kk
1001,  0,qq,qq
1002,  0,gg,gg就是,conNo相同的时候,取conbno最大的那个记录。

解决方案 »

  1.   

    select conNo ,f1,f2,max(conbno) from table1 group by conNo ,f1,f2;
      

  2.   

    不好意思,问题没有问清楚,如果不取出conbno,呢
    结果是这样的:
    1000, pp,kk
    1001, qq,qq
    1002, gg,gg
      

  3.   

    select conNo ,f1,f2,max(conbno) from table1 where conNO in (select distinct conNO from table1)
      

  4.   

    select conNo,f1,f2 from (select conNo ,f1,f2,max(conbno) from table1 group by conNo ,f1,f2)
      

  5.   

    select a.conNo,a.f1,a.f2 from table1 a,(select conNo,max(conbno) c1 from table1 group by conNo) b where a.conNo=b.conNo and a.conbno= b.c1