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 中的条件进行计数

      Count based on condition in SQL Server(根据 SQL Server 中的条件进行计数)
      <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 中的条件进行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Building a comma separated list?(建立一个逗号分隔的列表?)
                Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
              1. <tfoot id='Vuq5e'></tfoot>

                <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>
                          <tbody id='Vuq5e'></tbody>