订单按字段等于特定值? [英] Order By a field being equal to a specific value?
本文介绍了订单按字段等于特定值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这个MySQL查询:
Let's say I have this MySQL query:
SELECT * FROM A WHERE x='abc' OR y=0;
我如何确定行的优先级,以便首先对x='abc'
进行排序的情况?如果y=0
而不是x!='abc'
,我希望这些行排在x='abc'
的情况之后.
How can I prioritize the rows so that cases where x='abc'
are ordered FIRST? If y=0
but x!='abc'
, I want those rows to come after cases where x='abc'
.
这可以通过简单的ORDER BY子句完成吗?
Can this be accomplished with a simple ORDER BY clause?
谢谢!
推荐答案
SELECT *
FROM A
WHERE x='abc'
OR y=0
order by case when x='abc' then 0 else 1 end;
这篇关于订单按字段等于特定值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文