MySQL的自定义排序和Oracle相比,要简单得多。
假设在表v_education的列schoolRecord中,有以下字段:'小学','初中','高中','专科','本科','硕士','博士'。
mysql> describe v_education;
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| schoolRecord | varchar(20) | NO | | NULL | |
| number | bigint(21) | NO | | 0 | |
+--------------+-------------+------+-----+---------+-------+
如果想按照学历的从低到高排序,可以使用以下语句进行自定义排序
select * from v_education order by field(schoolRecord,'小学','初中','高中','专科','本科','硕士','博士')