In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
2025-11-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The Order by clause is used to sort the results, the order of execution is after the select clause, and the sort column is written in four ways:
Column_name
Column_alias, because the execution order of the order by clause is after the select clause, you can use the alias of the column
Nonnegative integer, which is used to indicate the position of column in the select clause, starting with 1
Column Expression
You can also specify multi-column sorting, each column can only appear once, the sorting rule is first sorted by the first column, then sorted by the second column, then sorted by the third column, and so on.
1, create sample table data
CREATE TABLE [dbo]. [dt_test] ([id] [int] NULL, [code] [int] NULL, [name] [varchar] (10) NULL)
2, use column name
Select id,code,name from dbo.dt_test dt with (nolock) order by dt.id
3. The reason why Alias can be used in the Column Alias,order by clause is that SQL Server Engine executes the select clause first, followed by the order by clause.
Select id as OrderID,code,name from dbo.dt_test dt with (nolock) order by OrderID
4. Use column order to sort, even if a positive integer is used to list the order of column in Select clause
Select id, code,name from dbo.dt_test dt with (nolock) order by 1
5. Use column expression to sort, in the order that the value of Column Expressino is calculated first, and then the results of the query are sorted.
Select id, code,name from dbo.dt_test dt with (nolock) order by id+code
6. Use column expression to sort, in the order that the value of Column Expressino is calculated first, and then the results of the query are sorted.
Select id, code,name from dbo.dt_test dt with (nolock) order by id%3
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.