标准SQL基本语句不支持top,麻烦,则要把TOP改写,根据排序字段
select top 4 * from #1
==》
select * from #1 a where
(select count(*) from #1 where id<=a.id and num<=a.num ) <=4
(要没有重复记录,而且按照排序选)
根据排序字段,这样可以吗?
select * from (
select *,seq=(select count(*) from #1 where id<=a.id and num<=a.num ) from #1 as a) as a
where seq>5
order by id,num
select a.* from sales a left join (select top 4 * from sales) b on
a.stor_id=b.stor_id and
a.ord_num=b.ord_num and
a.ord_date=b.ord_date and
a.qty=b.qty and
a.payterms=b.payterms and
a.title_id=b.title_id
where b.stor_id is null and
b.ord_num is null and
b.ord_date is null and
b.qty is null and
b.payterms is null and
b.title_id is null