Code select row_number() over(orderby merchantrequesttime desc) as pos,a.merchantid, a.payordercode,a.merchantrequesttime,b.visitorsrcpage into #tempfrom t_payorder a leftjoin t_visitor b on a.payordercode=b.ordercode where a.orderstatus=1 and a.merchantid='30e6bf9a-48f5-4dba-9b15-16aba9c0e55d'
selecttop10*from #tempwhere pos >(selectisnull(max(pos),0) from (selecttop20 pos from #temp) as t)