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换成你的自增字段
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
--应该是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
他那个要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
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
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换成你的自增字段
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
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
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
(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