Ordering以特定方式选择子句结果 [英] Ordering Select clause result in specific way

查看:115
本文介绍了Ordering以特定方式选择子句结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助编写选择子句查询。

I need help with writing a select clause query.

例如,我有一个像这样的查询:

For example, lets say I have a query like that:

select value from some_table order by value asc;

因此我得到:

1
2
3
4
5
6
7
8
9
10

但是我想写的特殊查询给我排序的值,但会在 8 之后输入 5

but a special query I want to write, is the one which still will give me sorted values, but will put 5 after 8.

我需要一个值来退出常规顺序。

this means I need one value to be out of regular order.

它可以用其他方式描述。让我说我有两组数字(例子):
A = {a | 1 <= a <= 118,a!= 78} B = {b |我有一个组C = AUBU {78}
和我需要所有这些值排序像A,78,B

it can be described in other way. lets say I have two groups of numbers (example): A={ a | 1<=a<=118, a!=78 } B={ b | b>118 } I have a group C=A U B U {78} and I need all these values sorted like "A,78,B"

推荐答案

假设值为整数,可以这样做:

Assuming value is integer, you could do this:

SELECT *
  FROM tbl
ORDER BY
       CASE
         WHEN value = 5 THEN 8.5
         ELSE value
       END

这篇关于Ordering以特定方式选择子句结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆