当前位置:网站首页>【mysql】mysql中行排序
【mysql】mysql中行排序
2022-07-06 20:50:00 【檀越剑指大厂】
mysql中行排序
1.数据准备
drop table if exists kwan.tmp_learning_mary;
create table if not exists kwan.tmp_learning_mary(
id varchar(10)
, name varchar(10)
,age varchar(10)
, salary int
);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (1, 'a', 10, 8000);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (1, 'a2', 11, 6500);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (2, 'b', 12, 13000);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (2, 'b2', 13, 4500);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (3, 'c', 14, 3000);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (3, 'c2', 15, 20000);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (4, 'd', 16, 30000);
insert into kwan.tmp_learning_mary(id, name, age, salary)
values (5, 'd2', 17, 1800);
2.编写sql加条件
select
*
from
(
select
*,
row_number() over(partition by id
order by
salary desc) ranking
from
tmp_learning_mary) t
where
t.ranking < 2;

3.编写sql不加条件
select
*
from
(
select
*,
row_number() over(partition by id
order by
salary desc) ranking
from
tmp_learning_mary) t

边栏推荐
- 哈夫曼树基本概念
- 什么是 BA ?BA怎么样?BA和BI是什么关系?
- About Estimation Statistics
- A 股指数成分数据 API 数据接口
- .net中 接口可以有默认实现了
- Sub pixel corner detection opencv cornersubpix
- R data analysis: how to predict Cox model and reproduce high score articles
- 23.(arcgis api for js篇)arcgis api for js椭圆采集(SketchViewModel)
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
- 密码学系列之:在线证书状态协议OCSP详解
猜你喜欢

QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式

Open3D 网格滤波

Open3d mesh filtering
Docker部署Mysql8的实现步骤

Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation

预处理——插值

RestClould ETL 社区版六月精选问答
接口数据安全保证的10种方式

【安全攻防】序列化与反序列,你了解多少?

Flink task exit process and failover mechanism
随机推荐
[dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
ubuntu20安装redisjson记录
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
Variables, process control and cursors (MySQL)
LAB1配置脚本
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
VHDL implementation of single cycle CPU design
注意力机制原理
22.(arcgis api for js篇)arcgis api for js圆采集(SketchViewModel)
Ubuntu20 installation redisjson record
Decoration design enterprise website management system source code (including mobile source code)
Kalman filter-1
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
1200.Minimum Absolute Difference
Mathematical induction and recursion
大白话高并发(二)
A 股指数成分数据 API 数据接口
Stored procedures and functions (MySQL)
MySQL的存储引擎
Flutter3.0了,小程序不止于移动应用跨端运行