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

      1. <tfoot id='5aFvM'></tfoot>
      2. <small id='5aFvM'></small><noframes id='5aFvM'>

        SELECT id HAVING id 的最大计数

        时间:2023-10-26

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

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

            <i id='7clLF'><tr id='7clLF'><dt id='7clLF'><q id='7clLF'><span id='7clLF'><b id='7clLF'><form id='7clLF'><ins id='7clLF'></ins><ul id='7clLF'></ul><sub id='7clLF'></sub></form><legend id='7clLF'></legend><bdo id='7clLF'><pre id='7clLF'><center id='7clLF'></center></pre></bdo></b><th id='7clLF'></th></span></q></dt></tr></i><div id='7clLF'><tfoot id='7clLF'></tfoot><dl id='7clLF'><fieldset id='7clLF'></fieldset></dl></div>
            <legend id='7clLF'><style id='7clLF'><dir id='7clLF'><q id='7clLF'></q></dir></style></legend>
              <tbody id='7clLF'></tbody>
                • <bdo id='7clLF'></bdo><ul id='7clLF'></ul>
                • 本文介绍了SELECT id HAVING id 的最大计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有一个带有 item_id 和 color_id 的产品表.我正在尝试使用最多的非空实例获取 color_id.

                  Have a products table with item_id and color_id. I'm trying to get the color_id with the most non-null instances.

                  这失败了:

                  SELECT color_id 
                    FROM products 
                   WHERE item_id=1234 
                   GROUP BY item_id 
                  HAVING MAX(COUNT(color_id))
                  

                  Invalid use of group function
                  

                  这个

                  SELECT color_id, COUNT(color_id)
                    FROM products 
                   WHERE item_id=1234 
                   GROUP BY item_id
                  

                  退货

                  color_id count
                  1, 323
                  2, 122
                  3, 554
                  

                  我正在寻找 color_id 3,它拥有最多的实例.

                  I am looking for color_id 3, which has the most instances.

                  是否有一种快速简便的方法无需 2 次查询即可获得我想要的东西?

                  Is there a quick and easy way of getting what I want without 2 queries?

                  推荐答案

                  SELECT color_id AS id, COUNT(color_id) AS count 
                  FROM products 
                  WHERE item_id = 1234 AND color_id IS NOT NULL 
                  GROUP BY color_id 
                  ORDER BY count DESC
                  LIMIT 1;
                  

                  这将为您提供 color_id 和该 color_id 的计数,按计数从最大到最小排序.我想这就是你想要的.

                  This will give you the color_id and the count on that color_id ordered by the count from greatest to least. I think this is what you want.

                  为了您的编辑...

                  SELECT color_id, COUNT(*) FROM products WHERE color_id = 3;
                  

                  这篇关于SELECT id HAVING id 的最大计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:ORA-01658: 无法为表空间 TS_DATA 中的段创建初始范围 下一篇:MySQL 选择年和月的第一天

                  相关文章

                    <tfoot id='uwJmb'></tfoot>

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

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