当前位置:网站首页>SQL server top 关键字使用
SQL server top 关键字使用
2022-07-27 16:28:00 【黑暗料理界的扛把子】
查询有时并非需要取出全部的数据,当我们只用到其中一部分时,就需要一些关键字配合。
MYSQL的关键字是limit,SQL server的关键字是top。
SQL server top 关键字的使用:
#取出数据的前三条
select top 3 * from table
#取出数据的前百分之20
select top 20 percent * from table
#从查询的200条数据中取出30-100条数据
with t as ( select top 200 row_number() over(order by uuid) r, * from table)
select * from t where r between 30 and 100
#从查询的200条数据中取出100条以后的数据
with t as ( select top 200 row_number() over(order by uuid) r, * from table)
select * from t where r >100MYSQL limit 关键字的使用
#含义是跳过2条取出1条数据,limit后面是从第2条开始读,读取1条信息,即读取第3条数据
select * from table limit 2,1;
#含义是从第1条(不包括)数据开始取出2条数据,limit后面跟的是2条数据,offset后面是从第1条开始读取,即读取第2,3条
select * from table limit 2 offset 1;
MYSQL limit 关键字的使用
/*Mysql limit offset示例
例1,假设数据库表student存在13条数据。
*/
#代码示例:
// 语句1和2均返回表student的第10、11、12、13行
语句1:select * from student limit 9,4
//语句2中的4表示返回4行,9表示从表的第十行开始
语句2:slect * from student limit 4 offset 9
例2,通过limit和offset 或只通过limit可以实现分页功能。
假设 numberperpage 表示每页要显示的条数,pagenumber表示页码,那么 返回第pagenumber页,每页条数为numberperpage的sql语句:
代码示例:
语句3:select * from studnet limit (pagenumber-1)*numberperpage,numberperpage
语句4:select * from student limit numberperpage offset (pagenumber-1)*numberperpage其他数据库相关内容
--假如我查到了1000条记录,我想取其中的第200~300条记录
--oracle:
with t as ( select rownum r, * from 表 where rownum<=300 )
select * from t where r>=200
--db2:
with t as ( select row_number() over(order by 字段) r, * from 表 fetch frist 300 rows only)
select * from t where r>=200
--其中 sqlserver\oracle\db2也可直接
with t as (select row_number() over(order by 字段) r, * from 表)
select * from t where r between 200 and 300
边栏推荐
- kettle引用外部脚本完成电话号码清洗、去重缩进
- Matrix of shell programming -- it's cute and cool
- Unity display Kinect depth data
- Some advice for NS2 beginner.
- Extension of ES6 value
- Role authorization --- complete the addition and deletion of secondary menus by adding and deleting primary menus
- 「测试新手百科」5 分钟快速上手Pytest 自动化测试框架
- Some advice for NS2 beginner.
- Kinect for Unity3d----KinectManager
- 换行问题双保险
猜你喜欢
随机推荐
[wechat applet] project practice - lottery application
WPS turns off annoying advertisements
How can I get started quickly when I change my career to soft testing and job hopping to a new company?
What if idea successfully connects to the database without displaying the table
Electromagnetic field learning notes - vector analysis and field theory foundation
There is a problem with the time zone when the idea connects to the database. The server returns invalid timezone is red Need to set ‘serverTimezone‘ property.
CMD command
专项测试之「 性能测试」总结
Unity显示Kinect捕获的镜头
express
ES6学习笔记(1)——快速入门
CMD 命令
Micaz+tinyos learning notes (1)
Kinect for Unity3d----KinectManager
Dynamic proxy
Learning notes of Microcomputer Principles - common addressing methods
Ridis command notes
web UI 自动化测试:Selenium 语法详解 史上最全
Mongodb learning notes (1) - install mongodb and its related configurations
WSN Journal indexed by SCI(转)









