0

This may seem silly, but what is the countifs equivalent in sql server? I have 2 columns, and want to count where both repeat. So if column 1 is date and there are 2 dates of 1/1/2016 and column 2 is name and there are 2 names of Bill, how would I show this as a 3rd column called count, which would produce the number 2 as the result?

jerry
  • 129
  • 1
  • 3
  • 10

2 Answers2

4

if you are using sql server 2005 + then you can use the OVER() clause with COUNT Over Clause info

select 
    date,
    name,
    count(*) over (partition by date, name) cnt
from 
    table
JamieD77
  • 13,796
  • 1
  • 17
  • 27
1
SELECT ColumDate, ColumName, COUNT(*) as Count
FROM Table
GROUP BY ColumDate, ColumName
Hassan
  • 1,413
  • 1
  • 10
  • 12