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

    • <bdo id='FdMZz'></bdo><ul id='FdMZz'></ul>

      1. <tfoot id='FdMZz'></tfoot>
        <i id='FdMZz'><tr id='FdMZz'><dt id='FdMZz'><q id='FdMZz'><span id='FdMZz'><b id='FdMZz'><form id='FdMZz'><ins id='FdMZz'></ins><ul id='FdMZz'></ul><sub id='FdMZz'></sub></form><legend id='FdMZz'></legend><bdo id='FdMZz'><pre id='FdMZz'><center id='FdMZz'></center></pre></bdo></b><th id='FdMZz'></th></span></q></dt></tr></i><div id='FdMZz'><tfoot id='FdMZz'></tfoot><dl id='FdMZz'><fieldset id='FdMZz'></fieldset></dl></div>
      2. <legend id='FdMZz'><style id='FdMZz'><dir id='FdMZz'><q id='FdMZz'></q></dir></style></legend>
      3. MySQL - IN() 中的 ORDER BY 值

        时间:2023-05-23

          • <bdo id='wbpbt'></bdo><ul id='wbpbt'></ul>
            <legend id='wbpbt'><style id='wbpbt'><dir id='wbpbt'><q id='wbpbt'></q></dir></style></legend>

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

            • <tfoot id='wbpbt'></tfoot>

                <i id='wbpbt'><tr id='wbpbt'><dt id='wbpbt'><q id='wbpbt'><span id='wbpbt'><b id='wbpbt'><form id='wbpbt'><ins id='wbpbt'></ins><ul id='wbpbt'></ul><sub id='wbpbt'></sub></form><legend id='wbpbt'></legend><bdo id='wbpbt'><pre id='wbpbt'><center id='wbpbt'></center></pre></bdo></b><th id='wbpbt'></th></span></q></dt></tr></i><div id='wbpbt'><tfoot id='wbpbt'></tfoot><dl id='wbpbt'><fieldset id='wbpbt'></fieldset></dl></div>
                  <tbody id='wbpbt'></tbody>
                • 本文介绍了MySQL - IN() 中的 ORDER BY 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我希望按照在 IN() 函数中输入的顺序对以下查询中返回的项目进行排序.

                  I'm hoping to sort the items returned in the following query by the order they're entered into the IN() function.

                  输入:

                  SELECT id, name FROM mytable WHERE name IN ('B', 'A', 'D', 'E', 'C');
                  

                  输出:

                  |   id   |   name  |
                  ^--------^---------^
                  |   5    |   B     |
                  |   6    |   B     |
                  |   1    |   D     |
                  |   15   |   E     |
                  |   17   |   E     |
                  |   9    |   C     |
                  |   18   |   C     |
                  

                  有什么想法吗?

                  推荐答案

                  SELECT id, name
                  FROM mytable
                  WHERE name IN ('B', 'A', 'D', 'E', 'C')
                  ORDER BY FIELD(name, 'B', 'A', 'D', 'E', 'C')
                  

                  FIELD 函数返回位置剩余字符串列表中的第一个字符串.

                  The FIELD function returns the position of the first string in the remaining list of strings.

                  但是,使用索引列来表示您的排序顺序,然后按此列排序,性能会好得多.

                  However, it is much better performance-wise to have an indexed column that represents your sort order, and then sort by this column.

                  这篇关于MySQL - IN() 中的 ORDER BY 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:node.js + mysql 连接池 下一篇:查找表中的列数

                  相关文章

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

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

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