当前位置:网站首页>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
边栏推荐
- Link with Game Glitch(spfa判负环)
- 2020美亚团队赛复盘
- Enterprise training and reproduction guidebook - training and reasoning of the OpenPose model based on Huawei ModelArts platform, realizing the recognition of two behaviors of climbing and climbing ov
- PWA 踩坑 - 第一次加载页面后无法获取CacheStorage某些资源
- 实例027:递归输出
- 暑假第五周总结
- mysql操作入门(四)-----数据排序(升序、降序、多字段排序)
- MySQL-数据库设计规范
- 在VMware上安装Metasploitable2
- SimpleChannelInboundHandler使用总结
猜你喜欢
随机推荐
Facebook社媒营销的5大技巧,迅速提高独立站转化率!
docker 安装mysql
使用hutool做本地缓存的工具类
张驰咨询:企业实施精益管理的最大障碍,只把精益作为一种工具和方法
OC-NSDictionary
张驰课堂:六西格玛测量系统的误差分析与判定
神经元网络
新产品立大功 伟世通第二季度营收双增
OC-NSNumber and NSValue are generally used for boxing and unboxing
实例027:递归输出
深度学习网络模型的改进与调整
有趣的网站
自然语言处理 文本预处理(下)(张量表示、文本数据分析、文本特征处理等)
php删除一维数组中一个值
线程的创建方式
C#重点问题之Struct和Class的异同
OC-范畴
Modify apt-get source to domestic mirror source
About the SQL concat () function problem, how to splice
59:第五章:开发admin管理服务:12:MongoDB的使用场景;(非核心数据,数据量比较大的非核心数据,人脸照片等隐私的小文件;)









