当前位置:网站首页>【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
边栏推荐
- Experience design details
- About Tolerance Intervals
- Optimization cases of complex factor calculation: deep imbalance, buying and selling pressure index, volatility calculation
- Jerry's transmitter crashed after the receiver shut down [chapter]
- Function reentry, function overloading and function rewriting are understood by yourself
- Index of MySQL
- Create applet from 0
- [dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
- Enumeration general interface & enumeration usage specification
- Ubuntu20 installation redisjson record
猜你喜欢
Mobile measurement and depth link platform - Branch
【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
如何自定义Latex停止运行的快捷键
VHDL implementation of arbitrary size matrix multiplication
Basic concepts of Huffman tree
VHDL实现任意大小矩阵加法运算
Docker部署Mysql8的实现步骤
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
数学归纳与递归
随机推荐
枚举通用接口&枚举使用规范
VHDL implementation of arbitrary size matrix addition operation
[security attack and Defense] how much do you know about serialization and deserialization?
A 股指数成分数据 API 数据接口
R数据分析:cox模型如何做预测,高分文章复现
Principle of attention mechanism
My brave way to line -- elaborate on what happens when the browser enters the URL
ubuntu20安裝redisjson記錄
卡尔曼滤波-1
Open3D 网格滤波
1200.Minimum Absolute Difference
校招行测笔试-数量关系
What about SSL certificate errors? Solutions to common SSL certificate errors in browsers
编译常量、ClassLoader类、系统类加载器深度探析
[leetcode] 450 and 98 (deletion and verification of binary search tree)
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
qt-线程等01概念
装饰设计企业网站管理系统源码(含手机版源码)
Can the applet run in its own app and realize live broadcast and connection?
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important