这是我想要得结果:
----------------------------------------------------
ID      CompanyID       ProductDetailID      Count
10      50              682                  A
14      60              689                  C
18      70              697                  E
-----------------------------------------------------

解决方案 »

  1.   

    select a.* 
    from 表 a,(select min(ID) as id,CompanyID,ProductDetailID 
               from 表 
               group by CompanyID,ProductDetailID ) b
    where a.id=b.id
      

  2.   

    select * from t,
    (select id=min(id),CompanyID,ProductDetailID from t group by ompanyID,ProductDetailID) a
    where t.id=a.id and t.CompanyID=a.CompanyID and t.ProductDetailID=a.ProductDetailID
      

  3.   

    select * from tb a where not exists (select * from tb  where companyid=a.companyid and productdetailid=a.productdetailid and id>a.id)
      

  4.   

    select 
          a.* 
    from
          tabname a 
    inner join    
          (select CompanyID,ProductDetailID ,min(ID) as ID
           from tabname 
           group by CompanyID,ProductDetailID ) b
    on
          a.CompanyID = b.CompanyID and a.ProductDetailID  = b.ProductDetailID and a.ID = b.ID
      

  5.   

    select * from 表 a 
    where not exists (select * from 表 where companyid=a.companyid and productdetailid=a.productdetailid and id<a.id)
      

  6.   

    select a.*,b.Count 
    from 
    (select min(ID) as id,CompanyID,ProductDetailID 
               from Table 
               group by CompanyID,ProductDetailID ) a 
    left join Table b on a.ID=b.ID  
      

  7.   

    楼主帮试下这个:
    select * from 表名 as a where not exists (select * from 表名 where CompanyID=a.CompanyID and ProductDetailID=a.ProductDetailID and [ID]<a.[ID])