Get the App
SLTechnology News&Howtos  ›  Database  › 

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

Shulou Source: shulou.com Published: 2022-05-31 19:26:13 09月20日 Update

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.

Tags: Unit function name field that is employee command salary flag format English classification grouping help sort clear number of people sequence content ascending order Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi OPPO Reno Linux Redmi Shulou Information