• <small id='NvLKd'></small><noframes id='NvLKd'>

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

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

        如何使用一个 SQL 查询获得多个计数?

        时间:2023-08-17
          <bdo id='ifEK0'></bdo><ul id='ifEK0'></ul>
              <i id='ifEK0'><tr id='ifEK0'><dt id='ifEK0'><q id='ifEK0'><span id='ifEK0'><b id='ifEK0'><form id='ifEK0'><ins id='ifEK0'></ins><ul id='ifEK0'></ul><sub id='ifEK0'></sub></form><legend id='ifEK0'></legend><bdo id='ifEK0'><pre id='ifEK0'><center id='ifEK0'></center></pre></bdo></b><th id='ifEK0'></th></span></q></dt></tr></i><div id='ifEK0'><tfoot id='ifEK0'></tfoot><dl id='ifEK0'><fieldset id='ifEK0'></fieldset></dl></div>

                1. <tfoot id='ifEK0'></tfoot>

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

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

                    <tbody id='ifEK0'></tbody>
                2. 本文介绍了如何使用一个 SQL 查询获得多个计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想知道如何编写此查询.

                  I am wondering how to write this query.

                  我知道这个实际的语法是假的,但它会帮助你理解我想要什么.我需要这种格式,因为它是更大查询的一部分.

                  I know this actual syntax is bogus, but it will help you understand what I am wanting. I need it in this format, because it is part of a much bigger query.

                  SELECT distributor_id, 
                  COUNT(*) AS TOTAL, 
                  COUNT(*) WHERE level = 'exec', 
                  COUNT(*) WHERE level = 'personal'
                  

                  我需要在一个查询中全部返回.

                  I need this all returned in one query.

                  另外,它需要在一行中,所以以下不起作用:

                  Also, it need to be in one row, so the following won't work:

                  'SELECT distributor_id, COUNT(*)
                  GROUP BY distributor_id'
                  

                  推荐答案

                  您可以将 CASE 语句与聚合函数一起使用.这与某些 RDBMS 中的 PIVOT 函数基本相同:

                  You can use a CASE statement with an aggregate function. This is basically the same thing as a PIVOT function in some RDBMS:

                  SELECT distributor_id,
                      count(*) AS total,
                      sum(case when level = 'exec' then 1 else 0 end) AS ExecCount,
                      sum(case when level = 'personal' then 1 else 0 end) AS PersonalCount
                  FROM yourtable
                  GROUP BY distributor_id
                  

                  这篇关于如何使用一个 SQL 查询获得多个计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:带有 Node.js 的 MySQL 下一篇:MySQL 无法添加外键约束

                  相关文章

                  最新文章

                3. <legend id='SSmPp'><style id='SSmPp'><dir id='SSmPp'><q id='SSmPp'></q></dir></style></legend>

                4. <i id='SSmPp'><tr id='SSmPp'><dt id='SSmPp'><q id='SSmPp'><span id='SSmPp'><b id='SSmPp'><form id='SSmPp'><ins id='SSmPp'></ins><ul id='SSmPp'></ul><sub id='SSmPp'></sub></form><legend id='SSmPp'></legend><bdo id='SSmPp'><pre id='SSmPp'><center id='SSmPp'></center></pre></bdo></b><th id='SSmPp'></th></span></q></dt></tr></i><div id='SSmPp'><tfoot id='SSmPp'></tfoot><dl id='SSmPp'><fieldset id='SSmPp'></fieldset></dl></div>
                5. <small id='SSmPp'></small><noframes id='SSmPp'>

                  1. <tfoot id='SSmPp'></tfoot>
                    • <bdo id='SSmPp'></bdo><ul id='SSmPp'></ul>