sql语句查询加分页

发布网友

我来回答

3个回答

热心网友

你的意思是前五行是固定的,后十行进行分页是么,前五行固定写死,后十行用参数或动态sql来进行分页。例如第一页:

select top 5 id,readcount,weight from table1 order by readcount desc
union all
select top 10,id,readcount,weight from table1 order by weight desc  --这句进行动态sql或传参数进行分页,网上分页的sql很多。

有问题再追问。

追问不是的,都是动态的,都需要分页

追答也没问题的,还是上面的格式,只是在top 5这句也加上动态sql

热心网友

with t as (select * from Table1 a order by weight)
select * from (
select top 5 t.*,'1' as num from t where readcount>10
union
(select top 10 t.*,'2' as num from t minus select top 5 t.*,'2' as num from t where readcount>10)
) order by num,weight

把前5个加上标签1,后10个加上标签2,最后按照标签排序就ok了

追问看不太懂。在能具体些吗?

追答你要问的是不是怎么让它按照你的意图排序?
那就union之后把前五个化作一组,后十个看作一组,按照组号排序,组内按照weight排序,那就和你的要求一样了

热心网友

select top 10 * from table

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com