Select a.*,b.productname
from TableA a
join TableB b on a.sortid = b.sortid
where b.id in (select top 3 id from tableB where sortid = b.sortid)
from TableA a
join TableB b on a.sortid = b.sortid
where b.id in (select top 3 id from tableB where sortid = b.sortid)
where id in( select top 3 id from 产品列表 a.sortid = sortid where group by sortid)