SQL:以其他方式排序的结果集的异常 [英] SQL: Exception to an otherwise sorted result set

查看:67
本文介绍了SQL:以其他方式排序的结果集的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Oracle 11g

Using Oracle 11g

我希望对其他排序表有一个例外情况

I want a single exception to an otherwise sorted table

select fruit as popluar_choices  
from menu 
order by fruit /* Exception put 'grapefruit' at top of list */

所需结果

popular_choices
-----------
grapefruit
apple
fig
kiwi
lemon
pear

类似于这篇文章: 如何应用非标准SQL列排序顺序?

推荐答案

  select fruit as popluar_choices  
    from menu 
order by case fruit when 'grapefruit' then 0
                                      else 1
              end,
         fruit

这篇关于SQL:以其他方式排序的结果集的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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