本文介绍了SQL Order By字符串列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在一个表上进行选择,并按某个关键字或关键字列表对结果进行排序.例如,我有一个像这样的表:

I wish to do a select on a table and order the results by a certain keyword or list of keywords. For example I have a table like so:

ID  Code
1   Health
2   Freeze
3   Phone
4   Phone
5   Health
6   Hot

所以,我不仅想做一个简单的Order By asc/desc,而且要order by Health, Phone, Freeze, Hot.这可能吗?

so rather than just do a simple Order By asc/desc I'd like to order by Health, Phone, Freeze, Hot. Is this possible?

推荐答案

尝试使用此功能:

select * from table
order by FIELD(Code, 'Health', 'Phone', 'Freeze', 'Hot')

这篇关于SQL Order By字符串列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 00:47