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

  1. <tfoot id='dFkFT'></tfoot>

      <legend id='dFkFT'><style id='dFkFT'><dir id='dFkFT'><q id='dFkFT'></q></dir></style></legend>
      <i id='dFkFT'><tr id='dFkFT'><dt id='dFkFT'><q id='dFkFT'><span id='dFkFT'><b id='dFkFT'><form id='dFkFT'><ins id='dFkFT'></ins><ul id='dFkFT'></ul><sub id='dFkFT'></sub></form><legend id='dFkFT'></legend><bdo id='dFkFT'><pre id='dFkFT'><center id='dFkFT'></center></pre></bdo></b><th id='dFkFT'></th></span></q></dt></tr></i><div id='dFkFT'><tfoot id='dFkFT'></tfoot><dl id='dFkFT'><fieldset id='dFkFT'></fieldset></dl></div>
        <bdo id='dFkFT'></bdo><ul id='dFkFT'></ul>
    1. MySQL 按一个数字排序,最后为空

      时间:2023-08-18
    2. <tfoot id='qbLhc'></tfoot>
    3. <legend id='qbLhc'><style id='qbLhc'><dir id='qbLhc'><q id='qbLhc'></q></dir></style></legend>
        <tbody id='qbLhc'></tbody>

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

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

                本文介绍了MySQL 按一个数字排序,最后为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                目前我正在做一个非常基本的 OrderBy 语句.

                Currently I am doing a very basic OrderBy in my statement.

                SELECT * FROM tablename WHERE visible=1 ORDER BY position ASC, id DESC
                

                这里的问题是位置"的 NULL 条目被视为 0.因此,所有位置为 NULL 的条目都出现在 1、2、3、4 的条目之前.例如:

                The problem with this is that NULL entries for 'position' are treated as 0. Therefore all entries with position as NULL appear before those with 1,2,3,4. eg:

                NULL, NULL, NULL, 1, 2, 3, 4
                

                有没有办法实现以下排序:

                Is there a way to achieve the following ordering:

                1, 2, 3, 4, NULL, NULL, NULL.
                

                推荐答案

                MySQL 有一个未公开的语法来最后对空值进行排序.在列名前放置一个减号 (-) 并将 ASC 切换为 DESC:

                MySQL has an undocumented syntax to sort nulls last. Place a minus sign (-) before the column name and switch the ASC to DESC:

                SELECT * FROM tablename WHERE visible=1 ORDER BY -position DESC, id DESC
                

                它本质上是 position DESC 的逆,将 NULL 值放在最后,但其他方面与 position ASC 相同.

                It is essentially the inverse of position DESC placing the NULL values last but otherwise the same as position ASC.

                这里有一个很好的参考http://troels.arvin.dk/db/rdbms#select-order_by

                这篇关于MySQL 按一个数字排序,最后为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何避免 MySQL '尝试获取锁时发现死锁;尝试 下一篇:如何获取 MySQL 的当前时区?

                相关文章

                最新文章

                <legend id='d6HEi'><style id='d6HEi'><dir id='d6HEi'><q id='d6HEi'></q></dir></style></legend>

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

                  3. <small id='d6HEi'></small><noframes id='d6HEi'>