开发者

sql- how to arrange the data in a table without use of asc keyword?

开发者 https://www.devze.com 2023-01-20 10:59 出处:网络
i have a table cal开发者_JAVA技巧led customer NameId ----- ---- vimal 34 arun56 sasi98 if i need to arrange those data in an alphabetical order we usually use query

i have a table cal开发者_JAVA技巧led customer

Name   Id
----- ----

vimal 34

arun  56

sasi  98

if i need to arrange those data in an alphabetical order we usually use query "select * from customer where order by name asc " similarly to reverse we use the query "select * from customer where order by name desc " without use of asc and desc keyword how to arrange or reverse the data's


;with cte as
(
select Id, name, row_number() over (order by name) rn 
from customer  
)
select Id, name
from cte 
order by rn /* (Or use -rn to sort descending)*/


Without using an ORDER BY clause the order of the returned data is completely arbitrary; it's whatever is most convenient for the server. You can drop the ASC as this is the default.

0

精彩评论

暂无评论...
验证码 换一张
取 消