之前用这条 select top 8 * from info_fair_job where batch_id =49 and is_stop = 0 order by quantity desc得到结果:现在我要得到 按Company_id 去重复操作。

解决方案 »

  1.   


    select top 8 * from info_fair_job a 
    where batch_id =49 and is_stop = 0 
    and not exists(select 1 from info_fair_job where Company_id=a.Company_id and quantity>a.quantity)
    order by quantity desc
    --猜的,如果不对,把quantity>a.quantity换成你的自增字段
      

  2.   

    select 
     top 8 * 
    from
     info_fair_job t
    where
      job_id=(select max(job_id) from info_fair_job  where Company_id=a.Company_id)
    order by
      quantity desc
      

  3.   

    --应该是tselect 
     top 8 * 
    from
     info_fair_job t
    where
      job_id=(select max(job_id) from info_fair_job  where Company_id=t.Company_id)
    order by
      quantity desc
      

  4.   

    他那个要a换成tselect top 8 * from info_fair_job a 
    where batch_id =49 and is_stop = 0 
    and not exists(select 1 from info_fair_job where Company_id=a.Company_id and job_id>a.job_id)
    order by quantity desc
      

  5.   

    SELECT b.* from
    (select TOP(8) company_id from info_fair_job where batch_id =49 and is_stop = 0 order by quantity desc) a
    CROSS APPLY
    (SELECT TOP(1) * FROM info_fair_job WHERE batch_id =49 and is_stop = 0 AND company_id = a.company_id ORDER BY quantity desc) b