在mysql中按某些标准排序 [英] Order column by certain criteria in mysql
本文介绍了在mysql中按某些标准排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用 MySQL
以适当的方式排序我的输出数据。
我目前使用的是 ORDER BY
并且所有内容都正常工作,直到现在。
I need to be able to order my output data in a proper way using MySQL
.
I'm using ORDER BY
so far and everything was working correctly until now.
我有这样的事情:
Table VEHICLES
:
ID | Name | MainGroup | SubGroup
1 | A | Vehicle | Truck
2 | B | Vehicle | Car
3 | C | Vehicle | Car
4 | D | Vehicle | Truck
5 | E | Vehicle | Truck
6 | F | Vehicle | Motorbike
我正在使用这个:
I was using this:
SELECT * FROM Vehicles WHERE MainGroup=Vehicle ORDER BY Subgroup;
当我得到选择时,他们没有以我想要的方式排序,因为现在我想成为能够确定选择的方式。假设我需要像汽车,卡车,摩托车
或其他方式的输出。如何实现这一目标?
这是可以使用顺序的
?
When I get selections they are not sorted in a way that I want, because now I want to be able to determine the way of the selected ones. Let's say that I want an output like this Car, Truck, Motorbike
or some other way around. How to achieve this?
Is this doable using an order by
?
推荐答案
使用 field()
:
SELECT *
FROM Vehicles
WHERE MainGroup=Vehicle
ORDER BY field(Subgroup, 'Car', 'Truck', 'Motorbike');
这篇关于在mysql中按某些标准排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文