<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

      SQL Group By with an Order By(带有 Order By 的 SQL Group By)
    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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                SQL query to group by day(按天分组的 SQL 查询)
                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 按组最频繁)
                Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                <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'>

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