当前位置:网站首页>Introduction to mysql operation (4) ----- data sorting (ascending, descending, multi-field sorting)
Introduction to mysql operation (4) ----- data sorting (ascending, descending, multi-field sorting)
2022-08-02 07:50:00 【web18224617243】
The content of the emp table is known as

1.Ascending
Syntax: select field name 1, field name 2, field name 3 from table name (where condition) order by (field);
Example: Sort salary in ascending order

You can also sort strings in ascending order, the order is according to the first letter, from a-z:

The default ordering of order by is ascending order. You can also add asc after order by (field) to indicate ascending order, and the effect is the same as the default.

2. Descending data order
Syntax: select field name 1, field name 2, field name 3 from table name (where condition) order by (field) desc;
Sort employees' salaries in descending order: (In ascending order by name when salaries are the same)

3. Sorting by multiple fields
When we sort in ascending order above, we found that when the salary is the same, the name ename is not sorted in ascending order.

Example: Arrange in ascending order of salary, and arrange in ascending order of name when the salary is the same.

Note: order by (field one) (ascending/descending), (field two) (ascending/descending), (field n) (ascending/descending)…
The field next to the order by plays a leading role together. When the first field in front cannot be judged, the second field in the back, field n, is used.
Sort by field index selected to find:
For example: select job,ename,sal from emp order by 1; //1 means the first field to be searched, that is, job, then the following is arranged in ascending order of jobs.If it is 2, it will be sorted in ascending order of ename.3 is sal..Anyway, this index is related to the position of the field you choose to find.

Simple exercise: Find out the employees whose jobs are SALESMAN in the emp table and sort them in descending order of salary.
sql statement: select ename,job,sal from emp where job='SALESMAN' order by sal desc;

Let me introduce myself first. The editor graduated from Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Ali in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
- 电商库存系统的防超卖和高并发扣减方案
- 条件构造器~wapper
- 企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
- 如何设计静态资源缓存方案
- ADS通信--倍福PLC和C#TextBox控件实现数据绑定的方法
- FormData upload binary file, object, object array
- 张驰课堂:六西格玛测量系统的误差分析与判定
- MySQL报错1055解决办法:[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
- MySQL-基础
- MySQL-慢查询日志
猜你喜欢
随机推荐
CSRF-跨站请求伪造-相关知识
Agile, DevOps and Embedded Systems Testing
深度学习网络模型的改进与调整
吃透Chisel语言.31.Chisel进阶之通信状态机(三)——Ready-Valid接口:定义、时序和Chisel中的实现
逆变器锁相原理及DSP实现
spark 读取本地文件
实例026:递归求阶乘
实例028:递归求等差数列
根据一个字段的内容去更新另一个字段的数据,这样的sql语句该怎么样书写
A Preliminary Study on the Basic Principles of Formal Methods
LeetCode刷题(7)
Link with Game Glitch(spfa判负环)
雷达人体存在感应器方案,智能物联网感知技术,实时感应人体存在
LeetCode 2360. The longest cycle in a graph
2022.07.31(LC_6132_使数组中所有元素都等于零)
FormData upload binary file, object, object array
概率论与数理统计
请教一下,Flink SQL ,JDBC sink 入 mysql 库,想要搞一个自增主键,要怎么写
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
【ROS基础】map、odom、base_link、laser 的理解 及其 tf 树的理解









