当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
在VMware上安装Metasploitable2
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
【杂】pip换国内源教程及国内源地址
View zombie processes
Splunk Filed Alias field name
实例026:递归求阶乘
【ROS基础】map、odom、base_link、laser 的理解 及其 tf 树的理解
新产品立大功 伟世通第二季度营收双增
【ROS基础】rosbag 的使用方法
LeetCode 2360. The longest cycle in a graph
LeetCode 2312. Sell Wood Blocks
【请教】SQL语句按列1去重来计算列2之和
【网络】IP、子网掩码
自然语言处理 文本预处理(上)(分词、词性标注、命名实体识别等)
“蔚来杯“2022牛客暑期多校训练营5,签到题KBGHFCD
2022年数据泄露平均成本高达435万美元,创历史新高!
获取间隔的日期列表工具类
倍福使用AdsRemote组件实现和C#的ADS通讯
逆变器锁相原理及DSP实现
Facebook社媒营销的5大技巧,迅速提高独立站转化率!



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





