• <bdo id='hjVRe'></bdo><ul id='hjVRe'></ul>
    <i id='hjVRe'><tr id='hjVRe'><dt id='hjVRe'><q id='hjVRe'><span id='hjVRe'><b id='hjVRe'><form id='hjVRe'><ins id='hjVRe'></ins><ul id='hjVRe'></ul><sub id='hjVRe'></sub></form><legend id='hjVRe'></legend><bdo id='hjVRe'><pre id='hjVRe'><center id='hjVRe'></center></pre></bdo></b><th id='hjVRe'></th></span></q></dt></tr></i><div id='hjVRe'><tfoot id='hjVRe'></tfoot><dl id='hjVRe'><fieldset id='hjVRe'></fieldset></dl></div>

    <small id='hjVRe'></small><noframes id='hjVRe'>

  1. <legend id='hjVRe'><style id='hjVRe'><dir id='hjVRe'><q id='hjVRe'></q></dir></style></legend>
    1. <tfoot id='hjVRe'></tfoot>

      Oracle SQL 中的自定义顺序

      Custom Order in Oracle SQL(Oracle SQL 中的自定义顺序)

      <i id='Bi8O4'><tr id='Bi8O4'><dt id='Bi8O4'><q id='Bi8O4'><span id='Bi8O4'><b id='Bi8O4'><form id='Bi8O4'><ins id='Bi8O4'></ins><ul id='Bi8O4'></ul><sub id='Bi8O4'></sub></form><legend id='Bi8O4'></legend><bdo id='Bi8O4'><pre id='Bi8O4'><center id='Bi8O4'></center></pre></bdo></b><th id='Bi8O4'></th></span></q></dt></tr></i><div id='Bi8O4'><tfoot id='Bi8O4'></tfoot><dl id='Bi8O4'><fieldset id='Bi8O4'></fieldset></dl></div>
        <tbody id='Bi8O4'></tbody>

          <small id='Bi8O4'></small><noframes id='Bi8O4'>

          1. <legend id='Bi8O4'><style id='Bi8O4'><dir id='Bi8O4'><q id='Bi8O4'></q></dir></style></legend>
          2. <tfoot id='Bi8O4'></tfoot>

                <bdo id='Bi8O4'></bdo><ul id='Bi8O4'></ul>
                本文介绍了Oracle SQL 中的自定义顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要根据货币订购交易.但是我需要实现一个自定义 order by,这使得 USD 总是排在最前面,其余的应该按 asc 排序.

                I need to order transaction based on the currency. However I need to implement a custom order by, which makes the USD to always comes on the top, and the rest should be ordered asc.

                例如:

                • BHT
                • 美元
                • 马币
                • JYP

                应该排序为:

                • 美元
                • BHT
                • 日元
                • 马币

                有没有简单的方法来处理这个问题?

                Is there a simple way to handle this?

                推荐答案

                不知道这样算不算简单:

                Don't know if this qualifies as simple:

                order by 
                    case 
                       when currency = 'USD' then 1 
                       when currency = 'BHT' then 2
                       when currency = 'JPY' then 3
                       when currency = 'MYR' then 4
                       else 5
                    end
                

                或者更紧凑但特定于 Oracle 的:

                or a bit more compact but Oracle specific:

                order by decode(currency, 'USD', 1, 'BHT', 2, 'JPY', 3, 'MYR', 4, 5)
                

                上述使用数字定义排序顺序的解决方案不会自动对 case/decode 表达式中未提及的货币进行正确排序.

                The above solution using numbers to defined the sort order will not automatically sort currencies correctly that aren't mentioned in the case/decode expression.

                为了简单地将美元放在前面而不关心其余部分,生成的"订单标准也必须是一个字符值.在这种情况下,您可以使用以下内容:

                To simply put USD at the front and don't care about the rest, the "generated" order criteria must be a character value as well. You can use the following in that case:

                order by 
                    case 
                       when currency = 'USD' then '001' 
                       else currency
                    end
                

                使用字母顺序"排序.这是有效的,因为字符在数字之后排序.(使用 'AAA' 而不是 '001' 也可以).

                Which uses an "alphabetical" ordering. This works because characters are sorted after the number digits. (Using 'AAA' instead of '001' would work as well).

                这篇关于Oracle SQL 中的自定义顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                SQL query to group by day(按天分组的 SQL 查询)
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                  <small id='ciA9u'></small><noframes id='ciA9u'>

                1. <legend id='ciA9u'><style id='ciA9u'><dir id='ciA9u'><q id='ciA9u'></q></dir></style></legend>

                2. <i id='ciA9u'><tr id='ciA9u'><dt id='ciA9u'><q id='ciA9u'><span id='ciA9u'><b id='ciA9u'><form id='ciA9u'><ins id='ciA9u'></ins><ul id='ciA9u'></ul><sub id='ciA9u'></sub></form><legend id='ciA9u'></legend><bdo id='ciA9u'><pre id='ciA9u'><center id='ciA9u'></center></pre></bdo></b><th id='ciA9u'></th></span></q></dt></tr></i><div id='ciA9u'><tfoot id='ciA9u'></tfoot><dl id='ciA9u'><fieldset id='ciA9u'></fieldset></dl></div>

                      <tbody id='ciA9u'></tbody>
                    <tfoot id='ciA9u'></tfoot>

                      <bdo id='ciA9u'></bdo><ul id='ciA9u'></ul>