Search
 
SCRIPT & CODE EXAMPLE
 

SQL

mysql order by on condition

 SELECT * 
    FROM my_table 
    WHERE 1  
    ORDER BY 
      CASE price WHEN 0 THEN 1
       ELSE -1
      END ASC, price asc, id asc
Comment

condition in orderby mysql

SELECT orders.status, orders.created_at
FROM `orders`
ORDER BY
  status='new' DESC,
  status='processing' DESC,
  CASE WHEN status IN ('new', 'processing') THEN created_at END ASC,
  CASE WHEN status NOT IN ('new', 'processing') THEN created_at END DESC
Comment

PREVIOUS NEXT
Code Example
Sql :: multiple values insert in sql 
Sql :: stored procedure vs view 
Sql :: oracle sql first day of quarter 
Sql :: sql split comma separated string into rows 
Sql :: backup table mssql 
Sql :: get month and year from date in mysql sequelize 
Sql :: pl/sql how to delete a trigger 
Sql :: pl sql round 
Sql :: xamarin sql lite create table if not exist 
Sql :: multiple tricky query in sql server 
Sql :: jooq finding lastest value in table 
Csharp :: count number of enum values C# 
Csharp :: c# calcualte proccess 
Csharp :: unity how to convert mouse screen position to world position 
Csharp :: how to edit text mesh pro text 
Csharp :: c# get pc ip address 
Csharp :: make winforms full-screen c# 
Csharp :: wpf label text in center 
Csharp :: how to change image color unity 
Csharp :: c# delete files older than x months 
Csharp :: how to change the color of your text in c# 
Csharp :: raycast shoot unity 
Csharp :: unity key pressed 
Csharp :: onafterrender blazor 
Csharp :: creatw list of int in C# 
Csharp :: 2d unity point at 
Csharp :: c# read file into a string 
Csharp :: get all files in all subdirectories c# 
Csharp :: unity game sleep on hit 
Csharp :: c# how to convert string to int 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =