Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sorting by value specific - ORDER BY

Tags:

sql

I am trying to sort a query using ORDER BY where I need to sort 3 columns one by one. And the third column is value specific.

Eg: If i have 3 columns a,b and c I need to use ORDER BY a, b desc, c='3' asc, c

What I want to do is first sort order is a, then b in desc order then I want the values of which has 3 to be sorted and then the remaining values which are not 3.

like image 700
Raviteja Avatar asked Dec 29 '22 05:12

Raviteja


1 Answers

 ORDER BY
  a,
  b desc,
  CASE WHEN c = 3 THEN 0 ELSE 1 END,
  c
like image 155
gbn Avatar answered Jan 04 '23 23:01

gbn