也许有人可以告诉我,如何在这种特定情况下订购MySQL输出:
我有这样的表:
| id | Value1 | Value2 | ...More values that doesn`t matter in this example
^-----^--------^--------^
| 1 | 1 | X |
| 2 | 2 | X |
| 3 | 3 | 2 |
| 4 | 1 | X |
| 5 | 2 | X |
| 6 | 3 | 3 |
| 7 | 1 | X |
| 8 | 2 | X |
| 9 | 3 | 1 |
我想从这个表中获取值,我想通过Value2对它们进行排序,但只有那里,其中Value1为3(X值无关紧要)。
最好的方法是什么,表现良好?
提前致谢!
答案 0 :(得分:2)
嗯,您想要where
和order by
吗?
select t.*
from t
where value1 = 3
order by value2;
编辑:
基于评论:
select t.*
from t
order by (value1 = 3) desc, -- put value 3 first
value2
答案 1 :(得分:0)
SELECT * FROM TABLE WHERE Value1=3 ORDER BY Value2
答案 2 :(得分:0)
请试试这个:
SELECT * FROM TABLE WHERE Value1=3 ORDER BY Value2 UNION SELECT * FROM TABLE WHERE Value1!=3