sql- how to arrange the data in a table without use of asc keyword?
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.
精彩评论