当前位置:网站首页>[MySQL] row sorting in MySQL
[MySQL] row sorting in MySQL
2022-07-07 03:48:00 【Tanyue Jianzhi Dachang】
mysql Bank of China sort
1. Data preparation
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. To write sql Conditional
select
*
from
(
select
*,
row_number() over(partition by id
order by
salary desc) ranking
from
tmp_learning_mary) t
where
t.ranking < 2;
3. To write sql Without conditions
select
*
from
(
select
*,
row_number() over(partition by id
order by
salary desc) ranking
from
tmp_learning_mary) t
边栏推荐
- 大白话高并发(二)
- Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
- 20. (ArcGIS API for JS) ArcGIS API for JS surface collection (sketchviewmodel)
- A 股指数成分数据 API 数据接口
- 2022年上半年HIT行业TOP50
- codeforces每日5题(均1700)-第七天
- When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
- Probability formula
- SSL证书部署
- Set WiFi automatic connection for raspberry pie
猜你喜欢
2022夏每日一题(一)
Set static IP for raspberry pie
How to customize the shortcut key for latex to stop running
Kalman filter-1
Can the applet run in its own app and realize live broadcast and connection?
Decoration design enterprise website management system source code (including mobile source code)
【安全攻防】序列化与反序列,你了解多少?
20.(arcgis api for js篇)arcgis api for js面采集(SketchViewModel)
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
随机推荐
本机mysql
QT opens a file and uses QFileDialog to obtain the file name, content, etc
浅谈网络安全之文件上传
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
The true face of function pointer in single chip microcomputer and the operation of callback function
函数重入、函数重载、函数重写自己理解
Can the applet run in its own app and realize live broadcast and connection?
Restcloud ETL Community Edition June featured Q & A
Set WiFi automatic connection for raspberry pie
Calculation of time and space complexity (notes of runners)
The latest 2022 review of "small sample deep learning image recognition"
SSL certificate deployment
Que savez - vous de la sérialisation et de l'anti - séquence?
Decoration design enterprise website management system source code (including mobile source code)
Index of MySQL
大白话高并发(二)
Principle of attention mechanism
SSL证书部署
【C语言】 题集 of Ⅸ
How to replace the backbone of the model