---
title: "多个字段 按要求的字段排序"
author: "cczzyc"
date: "2015-12-31T16:55:40Z"
tags: []
categories: ["数据库"]
slug: "untitled"
draft: false
lastmod: "2015-12-31T18:07:13Z"
id: 2267919
url: "https://hardworkbird.iteye.com/blog/2267919"
---

看例子

按照pay 等于4 的升序，

select * from cf\_loan\_application c  
order by  
decode(c.pay,'4',1,c.id)

 说明一下： 1 代表排在第几位

大家还可以在Order by中使用Decode。

例：表table\_subject，有subject\_name列。要求按照：语、数、外的顺序进行排序。这时，就可以非常轻松的使用Decode完成要求了。

select * from table\_subject order by decode(subject\_name, '语文', 1, '数学', 2, , '外语',3)