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

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
小众软件
小众软件
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
B
Blog
量子位
B
Blog RSS Feed
Vercel News
Vercel News
Blog — PlanetScale
Blog — PlanetScale
Last Week in AI
Last Week in AI
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
爱范儿
爱范儿
Jina AI
Jina AI
C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG

博客园 - 欢欢

写在跌后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