<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 个最大值?

        MySQL: Select top n max values?(MySQL:选择前 n 个最大值?)

        <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 个最大值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  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 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)
                • <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>
                          <tbody id='9sm9J'></tbody>
                          <bdo id='9sm9J'></bdo><ul id='9sm9J'></ul>