简体   繁体   中英

How do I count multiple columns in SQL Server?

I have a table like this:

在此输入图像描述

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

The column 'ID' will be ignored.

For this case, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM