PgSql 自定义排序和多条件排序

SELECT * FROM "records" 
-- record_status 自定义规则排序 
-- 先按照 record_status  ASC ,后按照 completed_at DESC
ORDER BY 
CASE record_status
WHEN 'evaluated' THEN 1
WHEN 'completed' THEN 2
WHEN 'processing' THEN 3
END ASC,
completed_at DESC

你可能感兴趣的:(PgSql 自定义排序和多条件排序)