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

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

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

        <tfoot id='rqEMB'></tfoot>

        MySQL:选择前 n 个最大值?

        时间:2023-05-23

        <small id='7AaHa'></small><noframes id='7AaHa'>

              <tfoot id='7AaHa'></tfoot>

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

                  <legend id='7AaHa'><style id='7AaHa'><dir id='7AaHa'><q id='7AaHa'></q></dir></style></legend>
                    <tbody id='7AaHa'></tbody>
                • 本文介绍了MySQL:选择前 n 个最大值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我对需要返回在特定列上具有最大值的前 N 行的查询感到非常困惑.

                  I am really confused about the query that needing to return top N rows having biggest values on particular column.

                  例如,如果行 N-1, N, N + 1 具有相同的值.我必须返回 只返回前 N 行前 N + 1 行.

                  For example, if the rows N-1, N, N + 1 have same values. Must I return just top N or top N + 1 rows.

                  推荐答案

                  如果你这样做:

                  select *
                  from t
                  order by value desc
                  limit N
                  

                  您将获得前 N 行.

                  如果你这样做:

                  select *
                  from t join
                       (select min(value) as cutoff
                        from (select value
                              from t
                              order by value
                              limit N
                             ) tlim
                      ) tlim
                      on t.value >= tlim;
                  

                  或者您可以更简单地将其表述为:

                  Or you could phrase this a bit more simply as:

                  select *
                  from t join
                       (select value
                        from t
                        order by value
                        limit N
                      ) tlim
                      on t.value = tlim.value;
                  

                  以下是您在概念上想要执行的操作,但它可能不适用于 MySQL:

                  The following is conceptually what you want to do, but it might not work in MySQL:

                  select *
                  from t
                  where t.value >= ANY (select value from t order by value limit N)
                  

                  这篇关于MySQL:选择前 n 个最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MySQL 错误 1436:线程堆栈溢出,带有简单查询 下一篇:来自变量的mysql字段名称

                  相关文章

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

                  <small id='9sm9J'></small><noframes id='9sm9J'>

                  <tfoot id='9sm9J'></tfoot>
                      <bdo id='9sm9J'></bdo><ul id='9sm9J'></ul>