当前位置:网站首页>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
边栏推荐
- 转行软测&跳槽到新公司,工作怎样快速上手?
- 图的遍历的定义以及深度优先搜索和广度优先搜索(二)
- How can I get started quickly when I change my career to soft testing and job hopping to a new company?
- 用Matlab生成适用于期刊及会议的图形- plot
- `this.$emit` 子组件给父组件传递多个参数
- NPM's ID card and dependence
- 怎样产生标准分布或高斯分布的随机数
- PHP字符串操作
- 浅谈基本的网络基本故障和问题排查
- 连续时间系统的性能分析(2)-二阶系统性能改善方式PID,PR
猜你喜欢

Subscription and use of Alibaba cloud video on demand service

CMD 命令

kettle 分列、合并记录

连续时间系统的性能分析(2)-二阶系统性能改善方式PID,PR

NPM basic use

"Testing novice encyclopedia" 5-minute quick start pytest automated testing framework

阿里云对象存储OSS的开通和使用

2022备战秋招10W字面试小抄pdf版,附操作系统、计算机网络面试题

编程式跳转

Performance analysis of continuous time systems (2) - second order system performance improvement methods PID, PR
随机推荐
Code interview of Amazon
mysql学习笔记(1)——变量
Unity learning notes (rigid body physics collider trigger)
Extension of ES6 value
X-shell remote connection virtual machine
An article allows you to master threads and thread pools, and also solves thread safety problems. Are you sure you want to take a look?
转行软测&跳槽到新公司,工作怎样快速上手?
webservice的疑问
Role authorization --- complete the addition and deletion of secondary menus by adding and deleting primary menus
WSN journal indexed by SCI
Unity-显示Kinect深度数据
新系统安装MySQL+SQLyog
Micaz+tinyos learning notes (1)
Product recommendation and classified product recommendation
[wechat applet] project practice - lottery application
Latex use - control the display position of tables or graphics
利用 Fastjson json (简单粗暴版)
win10小技巧(1)——转移桌面位置
收下这份实操案例,还怕不会用Jmeter接口测试工具
Learning notes of Microcomputer Principles - common addressing methods