SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
10,904 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello!
I know that order by can be used for sorting, and adding desc can be used to sort in descending order.
But now I need to move some of the last values to the middle, how do I do that?
Hi @15431565
You can use the case when statement in the order by.
Just like this.
create table test(col int);
insert into test values(4),(20),(36)
select * from test order by case when col = 4 then 1
when col = 20 then 3
when col = 36 then 2 end;
Output:
Best regards,
Percy Tang