CASE Usage in SQL

Problem: Write a query using the following table. The requirement is, result all the details " less than 20000" in ascending order and salary "greater than 20000" in descending order
NameSalary
Karthik25000
Samuel32000
John17000
Murali28000
Syam15000

Output should be

NameSalary
Syam15000
John17000
Samuel32000
Murali28000
Karthik25000


Query is:

Select * From Order by (Case When Salary <= 20000 Then -Salary Else null end) DESC,(Case When Salary > 20000 Then -Salary Else null end)

Comments

Popular posts from this blog

Network Intrusion Detection using Supervised ML technique

Common mistakes by Interviewer

Keep the system active, to avoid the auto lock