1. <small id='KTEhs'></small><noframes id='KTEhs'>

    2. <tfoot id='KTEhs'></tfoot>

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

      根据 SQL Server 中的条件进行计数

      时间:2023-10-10
      <tfoot id='c2yNK'></tfoot>

        <tbody id='c2yNK'></tbody>

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

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

                <legend id='c2yNK'><style id='c2yNK'><dir id='c2yNK'><q id='c2yNK'></q></dir></style></legend>
                本文介绍了根据 SQL Server 中的条件进行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有谁知道如何在 SQL Server 中根据条件进行计数.

                Does anyone know how can I do a count in SQL Server based on condition.

                示例:

                如何对名称为system"的记录进行列计数,以及表中的 CaseID 记录总数?

                How can I do a column count for records with name 'system', and total CaseID records in the table?

                客户表

                UserID     CaseID     Name
                1          100        alan
                1          101        alan
                1          102        amy
                1          103        system
                1          104        ken
                1          105        ken
                1          106        system  
                

                结果显示如下:

                UserID    TotalCaseID    TotalRecordsWithSystem
                1         7              2
                

                推荐答案

                使用 SUM/CASE...

                Use SUM/CASE...

                SELECT
                    COUNT(*),  --total
                    SUM(CASE WHEN name = 'system' THEN 1 ELSE 0 END) --conditional
                FROM
                    myTable
                

                这篇关于根据 SQL Server 中的条件进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:SQL Server:索引列用在什么地方? 下一篇:是否可以使用单个 UPDATE SQL 语句执行多个更新?

                相关文章

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

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

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

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

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