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

        <bdo id='nSvBK'></bdo><ul id='nSvBK'></ul>
    1. <legend id='nSvBK'><style id='nSvBK'><dir id='nSvBK'><q id='nSvBK'></q></dir></style></legend>

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

    2. 如何在 MySQL 中按 SUM() 排序?

      时间:2023-06-03

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

              <tbody id='UMKdh'></tbody>

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

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

                问题描述

                我有一张表:ID 名称 c_counts f_counts"

                I have a table: "ID name c_counts f_counts "

                我想通过 sum(c_counts+f_counts) 对所有记录进行排序但这不起作用:

                and I want to order all the record by sum(c_counts+f_counts) but this doesn't work:

                SELECT * FROM table ORDER BY sum(c_counts+f_counts) LIMIT 20;

                推荐答案

                别忘了,如果您混合分组(即 SUM)字段和非分组字段,则需要对非分组字段之一进行 GROUP BY字段.

                Don'y forget that if you are mixing grouped (ie. SUM) fields and non-grouped fields, you need to GROUP BY one of the non-grouped fields.

                试试这个:

                SELECT SUM(something) AS fieldname
                FROM tablename
                ORDER BY fieldname
                

                或者这个:

                SELECT Field1, SUM(something) AS Field2
                FROM tablename
                GROUP BY Field1
                ORDER BY Field2
                

                而且你总是可以像这样进行派生查询:

                And you can always do a derived query like this:

                SELECT
                   f1, f2
                FROM
                    (
                        SELECT SUM(x+y) as f1, foo as F2
                        FROM tablename 
                        GROUP BY f2
                    ) as table1
                ORDER BY 
                    f1
                

                多种可能性!

                这篇关于如何在 MySQL 中按 SUM() 排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 Visual Studio 中连接到 MySQL 数据源 下一篇:MYSQL count(*) 和 count(1) 哪个更好?

                相关文章

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

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

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