Reputation: 1101
I have a table like:
But I want to count the instances of my duplicate id's:
Any help would be appreciated.
Upvotes: 0
Views: 207
Reputation: 2063
Use ROW_NUMBER() function
SELECT id,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY id) AS idcnt,
x1,
x2
FROM tablename
Upvotes: 1
Reputation: 12969
This will be the syntax in MSSQL
CREATE TABLE #test(id int , x1 int, x2 int)
INSERT INTO #test(id,x1,x2) VALUES (1,1,1), (2,1,1), (2,2,2);
SELECT id
,ROW_NUMBER() OVER(PARTITION BY id ORDER BY id)
,x1
,x2
FROM #test
Upvotes: 2