怎么对 SQL 结果集排序,主要是因为查询出来的结果集没有索引列

2025-05-20 07:06:54
推荐回答(2个)
回答1:

你的sql其实取得就是6到10的内容。你试试在top10的集合做处理取出内容,免得在走表做链接。
没用过mssql,如果非要这么写的话,mssql里面应该有类似oracle的MINUS这样的函数吧,或者有没有类型with as()这样的临时表使用。

回答2:

select j.createcardid as id ,j.cardno as cardno from
(select top 10 l.createcardid,l.cardno from ec_store_card_info l ) j
left join
(select top 5 l.createcardid,l.cardno from ec_store_card_info l ) k
on k.cardno = j.cardno
where k.cardno is null order by 2