当前位置:网站首页>【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
边栏推荐
猜你喜欢
Clock in during winter vacation
哈夫曼树基本概念
Function reentry, function overloading and function rewriting are understood by yourself
源代码保密的意义和措施
华为小米互“抄作业”
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
维护万星开源向量数据库是什么体验
Can the applet run in its own app and realize live broadcast and connection?
Docker部署Mysql8的实现步骤
Que savez - vous de la sérialisation et de l'anti - séquence?
随机推荐
CMB's written test - quantitative relationship
Not All Points Are Equal Learning Highly Efficient Point-based Detectors for 3D LiDAR Point
What is Ba? How about Ba? What is the relationship between Ba and Bi?
存储过程与函数(MySQL)
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
[security attack and Defense] how much do you know about serialization and deserialization?
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)
Jerry's transmitter crashed after the receiver shut down [chapter]
[leetcode] 700 and 701 (search and insert of binary search tree)
Mathematical induction and recursion
Appx code signing Guide
How to customize the shortcut key for latex to stop running
本机mysql
概率论公式
注意力机制原理
Set static IP for raspberry pie
Sub pixel corner detection opencv cornersubpix
About Confidence Intervals
Numpy中排序操作partition,argpartition,sort,argsort
预处理——插值