惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
I
InfoQ
阮一峰的网络日志
阮一峰的网络日志
有赞技术团队
有赞技术团队
Vercel News
Vercel News
Engineering at Meta
Engineering at Meta
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
H
Help Net Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
V
Visual Studio Blog
B
Blog
MongoDB | Blog
MongoDB | Blog
T
The Blog of Author Tim Ferriss
L
LangChain Blog
D
Docker

博客园 - 欢欢

写在跌后C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssembliesC:\Program Files\Microsoft SQL Server\MSSQL.4\Reporting Services\ReportServer\bin - 欢欢 恋家 ASP.net操作Word的提示拒绝访问或open不动 默林 微软对联 好可爱的星座!(转) - 欢欢 - 博客园 爱因斯坦谜题解答(三种算法比较) w3wp.exe的进程占用了100% 今天也碰到这个问题,参考下面方法搞好了,非常感谢 CS0016: 未能写入输出文件 无线网络技术在物流管理中应用--家乐福大型连锁超市的应用案例 让无线使用更安全 无线设置详解 string code length .NET开源范例汇集贴 .NET Pet Shop 4.0.msi下载[.NET多层架构]地址 VS2005的中文版下载地址 http://thinhunan.cnblogs.com/favorite/42604.html NBear Project 高效的Session读写. NHibernate学习之路
查询数据库中满足条件的特定行数据
欢欢 · 2007-06-21 · via 博客园 - 欢欢

查询数据库中满足条件的特定行数据,在这里主要给出三条查询语句,其中第三条主要是针对SQL Server2005数据库的,因为其中的Row_Number()函数只有在SQL Server2005中才支持。
例子:
我数据库中有一个table表,表中一共有50条数据,我现在要查询第21到30条数据,我可以对这50条数据分成5页,每页10条数据。
一、select top 页大小 * from table1 where (id not in (select top (页大小-1)*每页数 id from 表 order by id))order by id
例子:select top 10 * from table where (id not in (select top 20 id from table order by id))order by id

二、select top 页大小 * from table1 where id>(select max (id) from (select top ((页码-1)*页大小) id from table1 order by id) as t) order by id
例子:select top 10 * from table where id>(select max (id) from (select top 20 id from table order by id) as t) order by id

总结:二比一好,not in费时

三、select * from(select ROW_NUMBER() over(order by id) -1 as rownum,table *  from
依据什么排序 默认行号为-1+1=0 table) as d where rownum between 0 and 10 起始行 显示多少行

例子:select * from(select ROW_NUMBER() over(order by ID desc) as rownum,table *  from table) as d where rownum between 21 and 30