当前位置:网站首页>Database - sorting data
Database - sorting data
2022-04-23 06:25:00 【Wood acridine】
This is the third literature following the above literature , This document is about the literature summary of sorting data in the database , Use SELECT When querying data from a table , The row order in the result set is not guaranteed . It means SQL Server You can return a result set with unspecified row order . The way to ensure that the rows in the result set are sorted is to use ORER BY Clause . Here are ORDER BY Syntax of clause :
In the above grammar ,column_name | expression - Specify the column name or expression to sort the query result set . If more than one column is specified , Sort by the first column of the result set , The sorting result set is then sorted by the second column , And so on .ORDER BY The columns appearing in the clause must correspond to the columns in the selection list or FROM Columns defined in the table specified in clause .
ASC | DESC - Use ASC or DESC Specifies whether the values in the specified column should be sorted in ascending or descending order . ASC Sort the results from the lowest value to the highest value , and DESC Sort the result set from the highest value to the lowest value . If you do not specify ASC or DESC , be SQL Server Use by default ASC To sort order . Besides ,SQL Server take NULL Regarded as the lowest value .
Processing has ORDER BY Clause SELECT When the sentence is , ORDER BY Clause is the last clause to be processed . Sort the result set in ascending order. The following statement sorts the customer list in ascending order by name : Sort the result set in descending order by one column. The following statement sorts the customer list in descending order by name . Sort the result set by multiple columns. The following statement retrieves the customer's name , Last name and city . It first sorts the list of customers by city , Then sort by name .
Sort the result set by multiple columns and in different order. The following statement sorts customers in descending order by city , Then sort the sorting results in ascending order according to the first name . Sort the result set by columns that are not in the selection list , Be careful , state Listed in customers It is defined in the table . If not , Then the query will be invalid . You can sort the result set by selecting columns that are not displayed in the list . for example , The following statement is as follows state Sort customers , Even if state The column is not displayed in the selection list .
Sort the result set by expression ,LEN() Function returns the number of characters in a string . The following sentence uses ORDER BY In Clause LEN() Function to retrieve a list of customers sorted by name length . Sort by the ordinal position of the column SQL Server Allows you to sort the result set according to the ordinal position of the columns displayed in the selection list . The following statement sorts customers by first name and last name . But it doesn't explicitly specify the column name , Instead, use the ordinal position of the column :
版权声明
本文为[Wood acridine]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210616404909.html
边栏推荐
猜你喜欢
[leetcode 54] spiral matrix
Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
Complete example demonstration of creating table to page - joint table query
線性代數第一章-行列式
Practical operation - Nacos installation and configuration
Denoising paper - [noise2void, cvpr19] noise2void learning denoising from single noise images
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
Understanding and installing MySQL
20 excellent plug-ins recommended by idea
随机推荐
Calculation (enter the calculation formula to get the result)
lambda expressions
In depth source code analysis servlet first program
PyTorch笔记——实现线性回归完整代码&手动或自动计算梯度代码对比
Kibana search syntax
Custom exception class
Doomsday (simple computational geometry)
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Problems and solutions of database migration
Three ways to create threads
Animation - Introduction to keyframes
[leetcode 19] delete the penultimate node of the linked list
Example of ticket selling with reentrant lock
Implementation of displaying database pictures to browser tables based on thymeleaf
去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
[leetcode217] there are duplicate elements
电机与拖动(戚金清版)学习整理
Contrôle automatique (version Han min)
[leetcode 6] zigzag transformation
线性代数第二章-矩阵及其运算