开发者

How do I count multiple columns in SQL Server?

I have a table like this:

How do I count multiple columns in SQL Server?

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

The column 'ID' will be ignored.

For this ca开发者_运维技巧se, the count result is 2.


How about:

 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 

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜