本文介绍了按查询的where子句中的字段顺序对sql查询的结果进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据查询的内容对查询结果进行排序:

I want to sort the result of this query according to the contains of the query :

在这里:

SELECT a from Frais a where a.libelle = 'FRET' or a.libelle = 'Douane' or a.libelle = 'Transitaire'

我想拥有先具有FRET而后具有Douane的记录,依此类推

I would like to have the records that have FRET first and Douane after and so on

order by libelle

无法解决按字母顺序升序或降序对它们进行排序的问题

doesn't resolve the problem it sort them according to alphabetic order asc or desc

推荐答案

SELECT a from Frais a where a.libelle = 'FRET' or a.libelle = 'Douane' or a.libelle = 'Transitaire'
order by case a.libelle when 'FRET' then 0 when 'Douane' then 1 when 'Transitaire' then 2 end

这篇关于按查询的where子句中的字段顺序对sql查询的结果进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 22:33