当前位置:网站首页>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
边栏推荐
- MySQL-锁机制
- php删除一维数组中一个值
- 暑假第五周总结
- Ask a question, my Flinkcdc has run through, I can monitor the binlog of msql, and I can also send kafk
- OC-NSDictionary
- LeetCode 2360. The longest cycle in a graph
- View zombie processes
- 有关 sql中的 concat()函数问题,如何拼接
- About the SQL concat () function problem, how to splice
- hdu1752 copy
猜你喜欢
随机推荐
Splunk Filed Alias 字段改名
牛客编程题中——需要处理输入较大数的题目
ADS通信--倍福PLC和C#TextBox控件实现数据绑定的方法
2020美亚团队赛复盘
吃透Chisel语言.31.Chisel进阶之通信状态机(三)——Ready-Valid接口:定义、时序和Chisel中的实现
电商库存系统的防超卖和高并发扣减方案
深度学习网络模型的改进与调整
Splunk Filed Alias field name
【云原生】如何快速部署Kubernetes
张驰课堂:六西格玛培训工具——箱线图
【机器学习】实验2布置:基于回归分析的大学综合得分预测
从云计算到函数计算
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
企业实训复现指导手册——基于华为ModelArts平台的OpenPose模型的训练和推理、基于关键点数据实现对攀爬和翻越护栏两种行为的识别、并完成在图片中只标注发生行为的人
【故障诊断分析】基于matlab FFT轴承故障诊断【含Matlab源码 2001期】
【杂】pip换国内源教程及国内源地址
有关 sql中的 concat()函数问题,如何拼接
倍福使用AdsRemote组件实现和C#的ADS通讯
查看端口号占用