当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
LeetCode 2360. 图中的最长环
Modify apt-get source to domestic mirror source
Splunk Filed Alias field name
MySQL-锁机制
【CV】OpenVINO安装教程
CollectionUtil:一个函数式风格的集合工具
About the SQL concat () function problem, how to splice
反射课后习题及做题记录
CSRF-跨站请求伪造-相关知识
SimpleChannelInboundHandler使用总结
【杂】pip换国内源教程及国内源地址
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
MySQL-FlinkCDC-Hudi enters the lake in real time
深度学习网络模型的改进与调整
初探形式化方法基本原理
【请教】SQL语句按列1去重来计算列2之和
SQL server 2014 怎么一次性导出多个查询结果?
问个问题,我的Flinkcdc已经跑通了,可以监听msql的binlog了,也能发送kafk
2022.07.31(LC_6132_使数组中所有元素都等于零)
封装class类一次性解决全屏问题

![WebGPU 导入[2] - 核心概念与重要机制解读](/img/8f/195a3b04912d8872d025df58ab5960.png)







