<tfoot id='xeNS8'></tfoot>

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

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

    1. <legend id='xeNS8'><style id='xeNS8'><dir id='xeNS8'><q id='xeNS8'></q></dir></style></legend>

      <i id='xeNS8'><tr id='xeNS8'><dt id='xeNS8'><q id='xeNS8'><span id='xeNS8'><b id='xeNS8'><form id='xeNS8'><ins id='xeNS8'></ins><ul id='xeNS8'></ul><sub id='xeNS8'></sub></form><legend id='xeNS8'></legend><bdo id='xeNS8'><pre id='xeNS8'><center id='xeNS8'></center></pre></bdo></b><th id='xeNS8'></th></span></q></dt></tr></i><div id='xeNS8'><tfoot id='xeNS8'></tfoot><dl id='xeNS8'><fieldset id='xeNS8'></fieldset></dl></div>
    2. 带有 Order By 的 SQL Group By

      时间:2023-06-02
    3. <legend id='KGTbn'><style id='KGTbn'><dir id='KGTbn'><q id='KGTbn'></q></dir></style></legend><tfoot id='KGTbn'></tfoot>

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

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

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

                  <tbody id='KGTbn'></tbody>

                本文介绍了带有 Order By 的 SQL Group By的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个标签表,想从列表中获取计数最高的标签.

                I have a table of tags and want to get the highest count tags from the list.

                示例数据如下

                id (1) tag ('night')
                id (2) tag ('awesome')
                id (3) tag ('night')
                

                使用

                SELECT COUNT(*), `Tag` from `images-tags`
                GROUP BY `Tag`
                

                让我完美地找回了我正在寻找的数据.但是,我想对它进行组织,以便标签计数最高的在前,并将其限制为仅向我发送前 20 个左右.

                gets me back the data I'm looking for perfectly. However, I would like to organize it, so that the highest tag counts are first, and limit it to only send me the first 20 or so.

                我试过了...

                SELECT COUNT(id), `Tag` from `images-tags`
                GROUP BY `Tag`
                ORDER BY COUNT(id) DESC
                LIMIT 20
                

                并且我不断收到无效使用组功能 - ErrNr 1111"

                and I keep getting an "Invalid use of group function - ErrNr 1111"

                我做错了什么?

                我使用的是 MySQL 4.1.25-Debian

                I'm using MySQL 4.1.25-Debian

                推荐答案

                在所有版本的 MySQL 中,只需为 SELECT 列表中的聚合取别名,并按别名排序:

                In all versions of MySQL, simply alias the aggregate in the SELECT list, and order by the alias:

                SELECT COUNT(id) AS theCount, `Tag` from `images-tags`
                GROUP BY `Tag`
                ORDER BY theCount DESC
                LIMIT 20
                

                这篇关于带有 Order By 的 SQL Group By的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:操作 '=' 的排序规则 (utf8_unicode_ci,IMPLICIT) 和 (utf8_gene 下一篇:加载数据文件错误代码:13

                相关文章

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

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

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

                    <tfoot id='m4LYq'></tfoot>