• <tfoot id='kDUAX'></tfoot>
  • <legend id='kDUAX'><style id='kDUAX'><dir id='kDUAX'><q id='kDUAX'></q></dir></style></legend>

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

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

    • <bdo id='kDUAX'></bdo><ul id='kDUAX'></ul>
      1. 如何在 mySQL 中定义自定义 ORDER BY 订单

        时间:2023-08-19
          1. <small id='iyGrA'></small><noframes id='iyGrA'>

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

                1. 本文介绍了如何在 mySQL 中定义自定义 ORDER BY 订单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 MySQL 中,我如何定义自定义排序顺序.

                  In MySQL how do I define a custom sorting order.

                  为了解释我想要什么,请考虑这张表:

                  To try to explain what I want consider this table:

                  ID  Language    Text
                  0   ENU         a
                  0   JPN         b
                  0   DAN         c       
                  1   ENU         d
                  1   JPN         e
                  1   DAN         f
                  2   etc...
                  

                  在这里我想返回按语言和升序 ID 排序的所有行,以便语言 = ENU 首先出现,然后是 JPN,最后是 DAN.

                  here I want to return all rows sorted by Language and ascending ID so that Language = ENU comes first, then JPN and lastly DAN.

                  结果应该是:a、d、b、e、c、f 等

                  The result should be: a,d,b,e,c,f etc.

                  这甚至可能吗?

                  推荐答案

                  MySQL 有一个方便的函数,叫做 FIELD() 非常适合此类任务.

                  MySQL has a handy function called FIELD() which is excellent for tasks like this.

                  ORDER BY FIELD(Language,'ENU','JPN','DAN'), ID

                  但是请注意

                  1. 它使您的 SQL 的可移植性降低,因为其他 DBMS 可能没有这种功能

                  1. It makes your SQL less portable, as other DBMSs might not have such function

                  当您的语言列表(或其他要排序的值)变得更长时,最好为它们创建一个带有 sortorder 列的单独表,并将其加入您的查询以进行排序.

                  When your list of languages (or other values to sort by) gets much longer, it's better to have a separate table with sortorder column for them, and join it to your queries for ordering.

                  这篇关于如何在 mySQL 中定义自定义 ORDER BY 订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 MySQL 中设置初始值和自动增量? 下一篇:从mysql的大表中快速选择随机行

                  相关文章

                  最新文章

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

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

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