Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between order by and group by in sql

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

SQL order by and group by what is the difference, many novices are not very clear about this, in order to help you solve this problem, the following small series will explain in detail for everyone, there are people who need this can learn, I hope you can gain something.

Order by is understood from English as the sorting method of rows. The default is ascending. Order by must be followed by the name of the sorted field, which can be multiple field names.

Group by is understood in English as grouping. Aggregate functions must be used with them, and at least one grouping flag field is required for use.

What is an "aggregate function"?

Like sum(), count(), avg(), etc. are "aggregate functions"

The purpose of group by is to categorize and summarize data.

Generally such as:

select unit name,count(employee id),sum(employee salary) form [a table]

group by Name of organization

The result of such operation is to count the number of employees and total wages of each unit with "unit name" as the classification mark.

Group by precedes order by in the order in which sql command formats are used.

The standard format of the select command is as follows:

SELECT select_list [ INTO new_table ] FROM table_source [ WHERE search_condition ] [ GROUP BY group_by_expression ] [ HAVING search_condition ] Is it helpful to read the above? If you still want to have further understanding of related knowledge or read more related articles, please pay attention to the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report