当前位置:网站首页>【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

边栏推荐
- 亚像素级角点检测Opencv-cornerSubPix
- Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
- Shell programming basics
- 【DPDK】dpdk样例源码解析之三:dpdk-l3fwd_001
- Appx code signing Guide
- Mathematical induction and recursion
- 体会设计细节
- Leetcode-02 (linked list question)
- 22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
- Open3D 网格滤波
猜你喜欢

注意力机制原理

Flutter3.0, the applet is not only run across mobile applications

Stored procedures and functions (MySQL)

如何自定义Latex停止运行的快捷键

2022.6.28

HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother

图形化工具打包YOLOv5,生成可执行文件EXE

codeforces每日5题(均1700)-第七天

My brave way to line -- elaborate on what happens when the browser enters the URL

Open3d mesh filtering
随机推荐
Index of MySQL
The latest 2022 review of "small sample deep learning image recognition"
23. (ArcGIS API for JS) ArcGIS API for JS ellipse collection (sketchviewmodel)
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
[leetcode] 700 and 701 (search and insert of binary search tree)
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
About Estimation Statistics
About Tolerance Intervals
2022年上半年HIT行业TOP50
Jerry's ble exiting Bluetooth mode card machine [chapter]
C# Task拓展方法
Ubuntu 20 installation des enregistrements redisjson
我的勇敢对线之路--详细阐述,浏览器输入URL发生了什么
Stored procedures and functions (MySQL)
ubuntu20安装redisjson记录
Shangsilicon Valley JVM Chapter 1 class loading subsystem
海思万能平台搭建:颜色空间转换YUV2RGB
【安全攻防】序列化与反序列,你了解多少?
Create applet from 0
It's too convenient. You can complete the code release and approval by nailing it!