当前位置:网站首页>Mysql rownum 实现
Mysql rownum 实现
2022-07-29 08:00:00 【律二萌萌哒】
Mysql查询显示行号,实现类似Oracle数据库的
ROWNUM()
在mysql数据库中没有ROWNUM()这个函数,只能通过变量的方式来实现.
需求:查询部门是技术开发,并按工资由低到高排序取第6条数据

create table employee(
name varchar(20),
dept varchar(20),
salary int
)
insert into employee values('李白','技术开发部',8000);
insert into employee values('赵云','技术开发部',9000);
insert into employee values('曹操','技术开发部',11000);
insert into employee values('关羽','技术开发部',13000);
insert into employee values('刘备','技术开发部',20000);
insert into employee values('小乔','技术开发部',25000);
insert into employee values('孙策','策划开发部',8500);
insert into employee values('马超','技术开发部',9600);
insert into employee values('张飞','需求开发部',12000);
insert into employee values('大乔','技术开发部',14000);
insert into employee values('典韦','需求开发部',21000);
insert into employee values('吕布','测试开发部',22000);
实现
-- @rownum 为自定义会话变量
-- @rownum := 0 确定初始值
-- @rownum := @rownum +1 步长
select *from
(select @rownum:=@rownum+1 as rownum,e.*
from employee e,(select @rownum:=0)t
where e.dept='技术开发部'
order by salary asc)c
where c.rownum=6
先排序

然后取出第六条

边栏推荐
- Compare three clock circuit schemes of single chip microcomputer
- 输出1234无重复的三位数
- [cryoelectron microscope] relation4.0 - subtomogram tutorial
- Dynamic thresholds buffer management in a shared buffer packet switch paper summary
- Solving linear programming problems based on MATLAB
- Phased learning about the entry-level application of SQL Server statements - necessary for job hunting (I)
- How to get to the deep-water area when the industrial Internet goes?
- [paper reading | cryoet] gum net: fast and accurate 3D subtomo image alignment and average unsupervised geometric matching
- 关于pip升级损坏导致的问题记录
- [cryoelectron microscope | paper reading] a feature guided, focused 3D signal permutation method for subtogram averaging
猜你喜欢
![[deep learning] data preparation -pytorch custom image segmentation data set loading](/img/7d/61be445febc140027b5d9d16db8d2e.png)
[deep learning] data preparation -pytorch custom image segmentation data set loading

What is the use of chat robots? What type? After reading these, you will understand!

Mqtt server setup and mqtt.fx testing

Do you want to meet all the needs of customers
![[flask introduction series] installation and configuration of flask Sqlalchemy](/img/62/3d108561f2cfeb182f8241192a79ba.png)
[flask introduction series] installation and configuration of flask Sqlalchemy

Chaos and future of domestic digital collections
![[paper reading] tomoalign: a novel approach to correcting sample motion and 3D CTF in cryoet](/img/3a/75c211f21758ca2d9bb1a40d739d80.png)
[paper reading] tomoalign: a novel approach to correcting sample motion and 3D CTF in cryoet

Realize the effect of changing some colors of a paragraph of text

Measured waveform of boot capacitor short circuit and open circuit of buck circuit

Excellent urban design ~ good! Design # visualization radio station will be broadcast soon
随机推荐
The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
UE4 highlight official reference value
In the MySQL connector of flynk CDC, the MySQL field is varbinary, which is officially
Basic introduction to pod
Dynamically load data
Some simple uses of crawler requests Library
[cryoelectron microscope] relion4.0 pipeline command summary (self use)
[dry goods memo] 50 kinds of Matplotlib scientific research paper drawing collection, including code implementation
《nlp入门+实战:第五章:使用pytorch中的API实现线性回归》
Technology sharing | quick intercom integrated dispatching system
CentOS deploy PostgreSQL 13
Mutationobserver document learning
"Swiss Army Knife" -nc in network tools
Monitor the bottom button of page scrolling position positioning (including the solution that page initialization positioning does not take effect on mouse sliding)
Realize the effect of changing some colors of a paragraph of text
Official tutorial redshift 01 basic theoretical knowledge and basic characteristics learning
CDM - code division multiplexing (easy to understand)
Volatile keyword parsing of C #
Shell script - global variables, local variables, environment variables
After the access database introduces DataGridView data, an error is displayed