Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The difference between order by and group by in sql
The difference between order by and group by in sql
1 has different meanings.

Order by means that in English, it is the sorting method of rows, and the default is ascending order. The sorted field names must be listed later, and can be multiple field names.

Group by means grouping in English. You must have an "aggregate function" to use it, and you need at least one group flag field when using it. ?

2. Different scope of application: order by is used for sorting, generally used together with asc ascending order or desc descending order. For example, select * order by column a from table a.

Group by is used for classification and summary, and is generally used with aggregate functions (such as avg average, sum total, max maximum, min minimum, count calculation line). For example, select month, sum (salary) as the total salary in the Monthly Salary Group.

3. Different definitions: order by mainly focuses on sorting a lot of data, such as sorting by size, while group by mainly focuses on grouping a lot of data, such as sorting by gender, age, country and discipline.

4. Different functions are used.

Columns in the order by clause must be contained in an aggregate function or a GROUP BY clause.

Is the function AVG () available in the group by clause? 、MIN()、MAX()? 、SUM()、COUNT().

5. What is the ordering basis? In English, it means the sort of rows, and the default is ascending. ? Sort by? The sorted field names must be listed later, and can be multiple field names.

Grouping basis? Understanding in English is grouping. You must have an "aggregate function" to use it, and you need at least one group flag field when using it.

Extended data

Microsoft Jet? Database engine? SQL data type consists of 13 basic data types, which are defined by Microsoft Jet database engine and several verified synonyms. Common ones are: plastic, single precision, double precision, variable-length characters, fixed-length characters, long type, date and so on.

You can use the ALTER TABLE statement to correct cardinality and increment. The row just inserted into the table has automatically generated values for the columns based on the new values and incremental values. If the value of new species and growth matches the value and increment of previous species, it will cause duplication. If this column is a primary key, copying values may cause errors when generating values.

Characters in a field defined as text (also called memo) or characters (also called text (n) with a specific length) are stored in a Unicode representation format.

Unicode characters always need two bytes to store each character. For the existing Microsoft Jet database, which mainly contains character data, this may mean that the word length of the database file will nearly double when it is converted to Microsoft Jet 4.0 format.

However, Unicode representations of many character groups previously represented by single byte character groups (SBCS) can be easily compressed into one byte. For more information about, see Creating a Table. If the CHAR column is defined with the COMPRESSION attribute, the data will be automatically compressed when stored and decompressed when extracted.

Baidu encyclopedia -SQL data type