mysql自定义多选排序_mysql实现自定义排序

mysql> select * from driver_log order by name;

+--------+-------+------------+-------+

| rec_id | name | trav_date | miles |

+--------+-------+------------+-------+

| 1 | Ben | 2006-08-30 | 152 |

| 9 | Ben | 2006-09-02 | 79 |

| 5 | Ben | 2006-08-29 | 131 |

| 8 | Henry | 2006-09-01 | 197 |

| 6 | Henry | 2006-08-26 | 115 |

| 4 | Henry | 2006-08-27 | 96 |

| 3 | Henry | 2006-08-29 | 300 |

| 10 | Henry | 2006-08-30 | 203 |

| 7 | Suzi | 2006-09-02 | 502 |

| 2 | Suzi | 2006-08-29 | 391 |

+--------+-------+------------+-------+

10 rows in set (0.00 sec)

mysql> select * from driver_log order by field(name,'Suzi','Ben','Henry');

+--------+-------+------------+-------+

| rec_id | name | trav_date | miles |

+--------+-------+------------+-------+

| 2 | Suzi | 2006-08-29 | 391 |

| 7 | Suzi | 2006-09-02 | 502 |

| 1 | Ben | 2006-08-30 | 152 |

| 9 | Ben | 2006-09-02 | 79 |

| 5 | Ben | 2006-08-29 | 131 |

| 8 | Henry | 2006-09-01 | 197 |

| 6 | Henry | 2006-08-26 | 115 |

| 4 | Henry | 2006-08-27 | 96 |

| 3 | Henry | 2006-08-29 | 300 |

| 10 | Henry | 2006-08-30 | 203 |

+--------+-------+------------+-------+

10 rows in set (0.00 sec)

mysql> select * from driver_log order by field(name,'Suzi','Ben');

+--------+-------+------------+-------+

| rec_id | name | trav_date | miles |

+--------+-------+------------+-------+

| 10 | Henry | 2006-08-30 | 203 |

| 8 | Henry | 2006-09-01 | 197 |

| 6 | Henry | 2006-08-26 | 115 |

| 4 | Henry | 2006-08-27 | 96 |

| 3 | Henry | 2006-08-29 | 300 |

| 7 | Suzi | 2006-09-02 | 502 |

| 2 | Suzi | 2006-08-29 | 391 |

| 5 | Ben | 2006-08-29 | 131 |

| 9 | Ben | 2006-09-02 | 79 |

| 1 | Ben | 2006-08-30 | 152 |

+--------+-------+------------+-------+

10 rows in set (0.00 sec)

mysql> select * from driver_log order by field(name,'Suzi','Ben') desc;

+--------+-------+------------+-------+

| rec_id | name | trav_date | miles |

+--------+-------+------------+-------+

| 1 | Ben | 2006-08-30 | 152 |

| 9 | Ben | 2006-09-02 | 79 |

| 5 | Ben | 2006-08-29 | 131 |

| 2 | Suzi | 2006-08-29 | 391 |

| 7 | Suzi | 2006-09-02 | 502 |

| 8 | Henry | 2006-09-01 | 197 |

| 6 | Henry | 2006-08-26 | 115 |

| 4 | Henry | 2006-08-27 | 96 |

| 3 | Henry | 2006-08-29 | 300 |

| 10 | Henry | 2006-08-30 | 203 |

+--------+-------+------------+-------+

10 rows in set (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值