我如何计算在SQL Server中的多个列? [英] How do I count multiple columns in SQL Server?

查看:188
本文介绍了我如何计算在SQL Server中的多个列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个表格:

我如何指望那些在列A,b,C,D?

How do I count rows that have identical values in columns A,B,C,D ?

列'ID'将被忽略。

The column 'ID' will be ignored.

有关这种情况下,计数结果是2

For this case, the count result is 2.

推荐答案

怎么样:

 SELECT COUNT(*), A, B, C, D
 FROM dbo.YourTable
 GROUP BY A, B, C, D
 -- optional - if you want to skip all the rows that occur only once
 -- HAVING COUNT(*) > 1 



基本上,你只需将数据分组由感兴趣的栏目,并让SQL算的行匹配每个组列值。

Basically, you just group your data by the columns of interest, and let SQL count the rows that match each set of column values.

这篇关于我如何计算在SQL Server中的多个列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆